From b5c16f0472b10f63ce1865433acefb3f36174395 Mon Sep 17 00:00:00 2001 From: Michael Santos Date: Sun, 16 Nov 2014 15:38:09 -0500 Subject: [PATCH] Fix the echo example 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. --- examples/echo.erl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/echo.erl b/examples/echo.erl index 075dc9b..2c26449 100644 --- a/examples/echo.erl +++ b/examples/echo.erl @@ -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) ->