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

Mazen Harake mazen@REDACTED
Mon Jun 25 16:25:11 CEST 2007


A good (better) idea would probably be to create the next state after
init as the accepting state...
E.g:
-module(tcptest_fsm).
-behaviour(gen_fsm).

init([Listen_socket] = Args) ->
{ok, conn_accept, SD}.

conn_accept(Listening_socket) ->
{ok, Socket} = gen_tcp:accept(Listen_socket),
{ok, conn_accept, SD}.

....

Listener then listens and gets {ok, LSock},
Then starts a gen_fsm and then send the first event with the LSock as
the argument.


On top of my head :)
Hope you follow what I mean :)

/Mazen

igwan wrote:
> 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 :
>
> -module(tcptest_fsm).
> -behaviour(gen_fsm).
>
> 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.
>
> igwan
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>   


-- 
Mazen Harake <mazen@REDACTED>
Erlang Software Developer and Consultant,
Erlang Training & Consulting, Ltd

Mobile Phone: +44 (0)795 13 26 317
Office Phone: +44 (0)207 45 61 020
Office Address:
401 London Fruit & Wool Exchange
Brushfield St, London, E1 6EL
United Kingdom

This email and its attachments may be confidential and are intended solely for the use of the individual to whom it is addressed. Any views or opinions expressed are solely those of the author and do not necessarily represent those of "Erlang Training & Consulting, Ltd".

If you are not the intended recipient of this email and its attachments, you must take no action based upon them, nor must you copy or show them to anyone. Please contact the sender if you believe you have received this email in error.




More information about the erlang-questions mailing list