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
Expand Up @@ -44,15 +44,16 @@ start(udp) ->
start(?PORT, [{protocol, udp}, {family, inet}, {type, dgram}]). start(?PORT, [{protocol, udp}, {family, inet}, {type, dgram}]).
start(Port, Options) -> start(Port, Options) ->
Protocol = proplists:get_value(protocol, Options, tcp), Protocol = proplists:get_value(protocol, Options, tcp),
Family = proplists:get_value(family, Options, inet),
{ok, Fd} = procket:open(Port, Options), {ok, Fd} = procket:open(Port, Options),
io:format("Listening on: ~p/~p~n", [Port, Protocol]), io:format("Listening on: ~p/~p~n", [Port, Protocol]),
listen(Protocol, Fd, Port). listen(Protocol, Family, Fd, Port).


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


accept(LS) -> accept(LS) ->
Expand Down

0 comments on commit c4fb02e

Please sign in to comment.