[erlang-questions] Dialyzer and gen_tcp:listen

Kostis Sagonas <>
Sat Dec 27 17:29:24 CET 2008


Koushik Narayanan wrote:
> Hi All,
> 
> The gen_tcp:listen function returns an {ok,ListenSocket} or {error,Reason} immediately.
> 
> But somehow for code like this:
> 
> init([Config_record]) ->
>         case inet:gethostbyname(Config_record#config.hostname) of
>                 {ok, {hostent, _HostName,_Unused,inet,_Ver,[IP]}} ->
>                                 HTTP_IP = IP;
>                 _ ->
>                         HTTP_IP = {127,0,0,1}
>         end,
>         {ok,Listen} = gen_tcp:listen(Config_record#config.port,[list,
>                                           {ip,HTTP_IP},
>                                           {packet,http},
>                                           {active, false},
>                                           {reuseaddr,true}]),
>         do_accept(Listen), %% returns immediately 
>         {ok,none}.
> 
> 
> The dialyzer says init/1 has no local return.
> 
> Why so?

Do yourself a favor and submit a proper bug report.  Some code that when 
you run dialyzer on it (btw, which Erlang/OTP version is this?), then it 
shows the behavior you claim dialyzer has on your code (and possibly any 
other warnings you may get).

With the information you have provided us, I cannot reproduce your 
problem. I put the above in a file:

------------------------------------------------------
-module(q).
-export([init/1]).

-record(config, {hostname, port}).

init([Config_record]) ->
     case inet:gethostbyname(Config_record#config.hostname) of
         {ok, {hostent, _HostName,_Unused,inet,_Ver,[IP]}} ->
             HTTP_IP = IP;
         _ ->
             HTTP_IP = {127,0,0,1}
     end,
    {ok,Listen} = gen_tcp:listen(Config_record#config.port,[list,
                                 {ip,HTTP_IP},
                                 {packet,http},
                                 {active, false},
                                 {reuseaddr,true}]),
    do_accept(Listen), %% returns immediately
    {ok,none}.

do_accept(_) -> ok.
------------------------------------------------------

and run dialyzer on it and got:

dialyzer -c q.erl
   Checking whether the PLT /home/kostis/.dialyzer_plt is up-to-date... yes
   Proceeding with analysis... done in 0m0.59s
done (passed successfully)


Kostis



More information about the erlang-questions mailing list