Skip to content

Commit

Permalink
Fix the echo example
Browse files Browse the repository at this point in the history
The behaviour of gen_tcp:listen/2 seems to have changed at some point:
if a non-zero port is passed in, the inet driver attempts to bind this
port, even if an 'fd' parameter exists in the options.

Setting the port to 0 seems to force inet to use the fd option.
  • Loading branch information
msantos committed Nov 16, 2014
1 parent 2f57493 commit b5c16f0
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions examples/echo.erl
Expand Up @@ -47,13 +47,13 @@ start(Port, Options) ->
Family = proplists:get_value(family, Options, inet),
{ok, Fd} = procket:open(Port, Options),
io:format("Listening on: ~p/~p~n", [Port, Protocol]),
listen(Protocol, Family, Fd, Port).
listen(Protocol, Family, Fd).

listen(tcp, Family, Fd, Port) ->
{ok, S} = gen_tcp:listen(Port, [binary, Family, {fd, Fd}]),
listen(tcp, Family, Fd) ->
{ok, S} = gen_tcp:listen(0, [binary, Family, {fd, Fd}]),
accept(S);
listen(udp, Family, Fd, Port) ->
{ok, S} = gen_udp:open(Port, [binary, Family, {fd, Fd}]),
listen(udp, Family, Fd) ->
{ok, S} = gen_udp:open(0, [binary, Family, {fd, Fd}]),
recv(S).

accept(LS) ->
Expand Down

0 comments on commit b5c16f0

Please sign in to comment.