Skip to content

Commit

Permalink
echo: pass in the protocol family to gen_*
Browse files Browse the repository at this point in the history
  • Loading branch information
msantos committed May 24, 2011
1 parent 5407f2b commit c4fb02e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions examples/echo.erl
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@ start(udp) ->
start(?PORT, [{protocol, udp}, {family, inet}, {type, dgram}]).
start(Port, Options) ->
Protocol = proplists:get_value(protocol, Options, tcp),
Family = proplists:get_value(family, Options, inet),
{ok, Fd} = procket:open(Port, Options),
io:format("Listening on: ~p/~p~n", [Port, Protocol]),
listen(Protocol, Fd, Port).
listen(Protocol, Family, Fd, Port).

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

accept(LS) ->
Expand Down

0 comments on commit c4fb02e

Please sign in to comment.