[erlang-questions] Erlang Latency Guide

Dmitry Vasiliev <>
Thu Nov 19 21:36:43 CET 2009


Erik Rigtorp wrote:
> For receiving there is a simple solution to this problem: use the {active,
> once} socket option.
> 
> A simple selective receive-free TCP receiver:
> 
> loop(Sock) ->
>     inet:setopts(Sock, [{active, once}]),
>     receive
>         {tcp, Sock, Data} ->
>             loop(Sock);
>         {tcp_error, Sock, Reason} ->
>             exit(Reason);
>         {tcp_closed, Sock} ->
>             exit()
>     end.

Does it mean {active, once} more optimal than {active, false}?

-- 
Dmitry Vasiliev <dima at hlabs.spb.ru>
http://hlabs.spb.ru
http://twitter.com/hdima


More information about the erlang-questions mailing list