From ad7efea77cdad5bba83529a7494b49d1e9a19ca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Wed, 4 Jul 2018 12:58:51 +0200 Subject: Return errors from Transport:handshake The "normal" errors are still silenced when calling ranch:handshake. --- src/ranch.erl | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'src/ranch.erl') diff --git a/src/ranch.erl b/src/ranch.erl index cab6e8f..9352ccc 100644 --- a/src/ranch.erl +++ b/src/ranch.erl @@ -228,9 +228,8 @@ child_spec(Ref, NumAcceptors, Transport, TransOpts0, Protocol, ProtoOpts) -spec accept_ack(ref()) -> ok. accept_ack(Ref) -> - receive {handshake, Ref, Transport, Socket, HandshakeTimeout} -> - Transport:accept_ack(Socket, HandshakeTimeout) - end. + {ok, _} = handshake(Ref), + ok. -spec handshake(ref()) -> {ok, ranch_transport:socket()}. handshake(Ref) -> @@ -238,8 +237,22 @@ handshake(Ref) -> -spec handshake(ref(), any()) -> {ok, ranch_transport:socket()}. handshake(Ref, Opts) -> - receive {handshake, Ref, Transport, Socket, HandshakeTimeout} -> - Transport:handshake(Socket, Opts, HandshakeTimeout) + receive {handshake, Ref, Transport, CSocket, HandshakeTimeout} -> + case Transport:handshake(CSocket, Opts, HandshakeTimeout) of + OK = {ok, _} -> + OK; + %% Garbage was most likely sent to the socket, don't error out. + {error, {tls_alert, _}} -> + ok = Transport:close(CSocket), + exit(normal); + %% Socket most likely stopped responding, don't error out. + {error, Reason} when Reason =:= timeout; Reason =:= closed -> + ok = Transport:close(CSocket), + exit(normal); + {error, Reason} -> + ok = Transport:close(CSocket), + error(Reason) + end end. -spec remove_connection(ref()) -> ok. -- cgit v1.2.3