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

Sergey A. <>
Wed Nov 26 21:45:11 CET 2008


Hello.

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

-------------------8<-------------------
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)
-------------------8<-------------------

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.

Thanks.

--
Sergey.



More information about the erlang-questions mailing list