[erlang-questions] Why is setting socket options by setopts() better than by listen()?

Sergey A. n39052@REDACTED
Wed Nov 26 21:45:11 CET 2008


I've read the following in the "Programming Erlang":

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}]),

And I have a small question. Why that is considered better solution
than using the same options, but passed to gen_tcp:listen/2 function:

gen_tcp:listen(2345, [{packet, 4}, binary, {nodelay, true}, {active,
true}, {reuseaddr, true}])

As I know, all the sockets obtained by calling gen_tcp:accept/1
inherit options listed in gen_tcp:listen.



More information about the erlang-questions mailing list