[erlang-questions] How to solve the blocking accept call in a tcp_listener process ?

Howard Yeh hayeah@REDACTED
Wed May 27 23:49:18 CEST 2009


you could probably try using the active once option. Don't know if
this is what you need.

Open the socket like this,

{ok,Sock} = gen_tcp:listen(Port,[binary,{active,false}]),

Then when you need data,

socket_receive(Sock) ->
  inet:setopts(Sock,[{active,once}]),
  receive
    {tcp,Sock,Bin} -> Bin
  end.

it allows the socket to send exactly one tcp message to the owner
process. Since it's in the mailbox, you can process it asynchronously.


On Tue, May 19, 2009 at 2:38 AM, info <info@REDACTED> wrote:
> Hi all,
> Many examples uses the async_accept primitive from the module prim_inet.
> This primitive is not documented (low level) and might change or dissapear.
> Do you know examples which don't use it but use a "clean" solution for the
> blocking accept call ?
> Or could you show an elegant solution in this forum ?
>
> J-Ph. Constantin
> info@REDACTED
> meyrin/geneva
> switzerland
> +41793265281
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



-- 
blog: www.metacircus.com


More information about the erlang-questions mailing list