[erlang-questions 73] Re: dialyzer and ssl

Ingela Andin <>
Mon Mar 28 08:58:55 CEST 2011


Hi!

2011/3/24 Roberto Ostinelli <>:
> dear list,
>
> i'm getting this dialyzer warning i cannot understand:
>
> "The pattern 'ok' can never match the type {'error',_} |
> {'ok',{'sslsocket',_,_}}"
>
> this points to line 4 of this code extract:
>
> 1. case ssl:transport_accept(ListenSocket) of
> 2.    {ok, {sslsocket, _, _} = Sock} ->

You should not match a record as its tuple representation, it breaks the
abstraction and possible your code if we add a record field, and in this
case the record is not documented either, the "sslsocket" is documented to
be opaque to the user so you ought to match only {ok, Socket}


> 3.        case ssl:ssl_accept(Sock, 60000) of
> 4.            ok ->
>                 ...
> 5.            {error, _Reason} ->
>                 ...
> 6.        end
> 7.    {error, _Reason} ->
>         ...
> 8. end
>
> afaik, ssl_accept/2 returns ok | {error, Reason} as per the specs:
> http://www.erlang.org/doc/man/ssl.html#ssl_accept-2
>
> is this due to some discrepancy in docs/specs? or am i missing something?

As for ssl:ssl_accept/2 it can return both ok and {ok, Socket} the
latter will be returned if you upgrade
a tcp-socket to an ssl-socket and ok will be returned in the normal
case to retain backwards compatibility. (You
already have access to the sslsocket from the transport_accept in this
case).  This is documented even in r13.

We wanted to return {ok, Socket} in both cases but we had to
priorities the backwards compatibility so
not using the latest version could very well result in discrepancies,
but I have not looked deeper to
verify  what is your  actual problem.

Regards Ingela Erlang/OTP team - Ericsson AB



More information about the erlang-questions mailing list