[erlang-questions] gen_tcp:accept use within a gen_fsm process

igwan igwan@REDACTED
Mon Jun 25 13:41:48 CEST 2007

Hello list,

I'm writing a small TCP test application. I want each TCP connection to 
be handled by one gen_fsm process. I could have one 'acceptor' process 
calling gen_tcp:accept, then spawning a gen_fsm for each accepted 
incoming connection. But in the doc, I read that, since a recent version 
of Erlang/OTP, I can have any number of processes waiting in a 
gen_tcp:accept call, so I wouldn't need the acceptor process anymore. My 
question is about best practice. Where would you call gen_tcp:accept in 
the gen_fsm module ? Into the init/1 function ? Like this :


init([Listen_socket] = Args) ->
    {ok, Socket} = gen_tcp:accept(Listen_socket),
    {ok, conn_accepted_state, SD}.

I'm not very confident about puting such a blocking call at the init 
phase as the process wouldn't be initialized until a connection arrives 
and thus not supervised (Am I right ?).
Or maybe the new possibility offered by gen_tcp:accept wasn't intended 
for use within a OTP system ?

Thanks for your help.


More information about the erlang-questions mailing list