ssl and {active, once} - bug?

Roberto Ostinelli roberto@REDACTED
Sun Apr 11 13:49:28 CEST 2010


dear all,

i really hope some kind sould can take me out of this.

i'm using ssl to provide an https service. i start a ssl listener with
the following options:

[binary, {packet,http}, {ip,{0,0,0,0}}, {reuseaddr,true},
{active,false}, {backlog,128},
{certfile, "/Users/roberto/Code/test/server.pem"},
{keyfile, "/Users/roberto/Code/test/privkey.pem"},
{password,"test"}]

once i have the listening socket, i accept incoming requests like this:

accept(ListenSocket) ->
	case ssl:transport_accept(ListenSocket) of
		{ok, NewSocket} ->
			case ssl:ssl_accept(NewSocket) of
				ok -> {ok, NewSocket};
				{error, Reason} -> {error, Reason}
			end;
		{error, Reason} -> {error, Reason}
	end.

once i get the NewSocket, i spawn a controlling process with Pid and i
set it as controller of NewSocket:

ssl:controlling_process(NewSocket, Pid)

the controlling process has the following loop [abstract]:

request(#c{sock = Sock, recv_timeout = RecvTimeout} = C, Req) ->
	ssl:setopts(Sock, [{active, once}]),
	?LOG_DEBUG("waiting http request line", []),
	receive
		{ssl, Sock, {http_request, Method, Path, Version}} ->
			?LOG_DEBUG("received full headers of a new HTTP packet", []),
			headers(C, Req#req{vsn = Version, method = Method, uri = Path,
connection = default_connection(Version)}, []);
		{ssl, Sock, {http_error, "\r\n"}} ->
			request(C, Req);
		{ssl, Sock, {http_error, "\n"}} ->
			request(C, Req);
		{ssl, Sock, _Other} when is_list(_Other) ->
			?LOG_WARNING("invalid tcp data received for ~p socked :~p",
[SocketMode, _Other]),
			exit(normal);
		_Other ->
			?LOG_WARNING("tcp error on incoming request: ~p", [_Other]),
			exit({error, unknown data});
	after RecvTimeout ->
		?LOG_DEBUG("normal receive timeout, exit", []),
		close(Sock, SocketMode),
		exit(normal)
	end.


when i run my server and i point a browser to localhost, it all goes
perfectly until i see the debug log "waiting http request line"
printed in console, then i get:

=ERROR REPORT==== 11-Apr-2010::13:21:45 ===
** Generic server <0.45.0> terminating
** Last message in was {http,#Port<0.611>,
                             {http_request,'GET',{abs_path,"/?id=2"},{1,1}}}
** When Server state == {st,acceptor,<0.42.0>,<0.47.0>,<0.47.0>,6,once,
                            [{mode,binary},
                             {packet,http},
                             {ip,{0,0,0,0}},
                             {active,once},
                             {nodelay,false},
                             {verify,0},
                             {depth,1}],
                            {sslsocket,6,<0.45.0>},
                            #Port<0.611>,50664,open,true,false}
** Reason for termination ==
** {error,{badinfo,{http,#Port<0.611>,
                         {http_request,'GET',{abs_path,"/"},{1,1}}}}}


now:

1. i see that the incoming message has format {http, Sock, Data}.
shouldn't it be {ssl, Sock, Data} as per
http://www.erlang.org/doc/man/ssl.html:

"When a socket is in active mode (the default), data from the socket
is delivered to the owner of the socket in the form of messages:

    * {ssl, Socket, Data}
    * {ssl_closed, Socket}
    * {ssl_error, Socket, Reason}"

i'm using R13B01 so maybe this has changed.

2. why am i receiving a badinfo message ["Call not recognized for
current mode (active or passive) and state of socket"], and what can i
do to solve this?


thank you in advance,

r.


More information about the erlang-questions mailing list