ssl and {active, once} - bug?

Roberto Ostinelli <>
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"},

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}
		{error, Reason} -> {error, Reason}

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", []),
		{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]),
		_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),

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>,
** When Server state == {st,acceptor,<0.42.0>,<0.47.0>,<0.47.0>,6,once,
** Reason for termination ==
** {error,{badinfo,{http,#Port<0.611>,


1. i see that the incoming message has format {http, Sock, Data}.
shouldn't it be {ssl, Sock, Data} as per

"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,


More information about the erlang-questions mailing list