[erlang-questions] Setting socket options on listen / accept

Tianxiang Xiong tianxiang.xiong@REDACTED
Tue Feb 6 06:55:03 CET 2018


In Joe's Programming Erlang 2nd E
<https://pragprog.com/book/jaerlang2/programming-erlang>, Chpt. 17, pg.
274, he says:

After we have accepted a connection, it’s a good idea to explicitly set the
> required socket options, like this:


{ok, Socket} = gen_tcp:accept(Listen),
inet:setopts(Socket, [{packet,4},binary,{nodelay,true},{active, true}]),
loop(Socket)

Until then the book's been doing:

{ok, Listen} = gen_tcp:listen(2345, [binary, {packet, 4}, {reuseaddr,
true}, {active, true}])
{ok, Socket} = gen_tcp:accept(Listen),
...
loop(Socket)

Is there a reason we need to set the options after accept? Is it necessary
to set options on listen *and* accept?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180205/42a3676a/attachment.htm>


More information about the erlang-questions mailing list