Skip to content
Browse files

echo: pass in the protocol family to gen_*

  • Loading branch information...
1 parent 5407f2b commit c4fb02ebf8a2d7ce032ee7978378bf952777dfe6 @msantos committed
Showing with 6 additions and 5 deletions.
  1. +6 −5 examples/echo.erl
View
11 examples/echo.erl
@@ -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) ->

0 comments on commit c4fb02e

Please sign in to comment.
Something went wrong with that request. Please try again.