aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2016-11-15 14:06:15 +0200
committerLoïc Hoguin <[email protected]>2016-11-15 14:09:50 +0200
commitcf85152fff8fc09a8c95fdc1b24db274defb052e (patch)
tree7ab66dbd20c7b66fa59a84350f5c39ac9fd868c6 /examples
parent2c93d8ef43dbae0f9a9a44d1c70d28195f2a0a40 (diff)
downloadranch-cf85152fff8fc09a8c95fdc1b24db274defb052e.tar.gz
ranch-cf85152fff8fc09a8c95fdc1b24db274defb052e.tar.bz2
ranch-cf85152fff8fc09a8c95fdc1b24db274defb052e.zip
Properly handle Ctrl+D in examples
Diffstat (limited to 'examples')
-rw-r--r--examples/tcp_echo/src/echo_protocol.erl2
-rw-r--r--examples/tcp_reverse/src/reverse_protocol.erl3
2 files changed, 3 insertions, 2 deletions
diff --git a/examples/tcp_echo/src/echo_protocol.erl b/examples/tcp_echo/src/echo_protocol.erl
index 5ed79b3..6e1df40 100644
--- a/examples/tcp_echo/src/echo_protocol.erl
+++ b/examples/tcp_echo/src/echo_protocol.erl
@@ -16,7 +16,7 @@ init(Ref, Socket, Transport, _Opts = []) ->
loop(Socket, Transport) ->
case Transport:recv(Socket, 0, 5000) of
- {ok, Data} ->
+ {ok, Data} when Data =/= <<4>> ->
Transport:send(Socket, Data),
loop(Socket, Transport);
_ ->
diff --git a/examples/tcp_reverse/src/reverse_protocol.erl b/examples/tcp_reverse/src/reverse_protocol.erl
index 2c7c15b..80ed62c 100644
--- a/examples/tcp_reverse/src/reverse_protocol.erl
+++ b/examples/tcp_reverse/src/reverse_protocol.erl
@@ -38,7 +38,8 @@ init({Ref, Socket, Transport, _Opts = []}) ->
?TIMEOUT).
handle_info({tcp, Socket, Data}, State=#state{
- socket=Socket, transport=Transport}) ->
+ socket=Socket, transport=Transport})
+ when byte_size(Data) > 1 ->
Transport:setopts(Socket, [{active, once}]),
Transport:send(Socket, reverse_binary(Data)),
{noreply, State, ?TIMEOUT};