Handle errors in start_link (tcp_closed)

This commit is contained in:
Hans Svensson 2018-04-17 09:00:22 +02:00
parent 41b8efd201
commit fc510c07a1
2 changed files with 14 additions and 8 deletions

View File

@ -237,8 +237,10 @@ tcp_handshake(TcpSock, Role, Options) ->
case handshake(Options, Role, ComState) of case handshake(Options, Role, ComState) of
{ok, #{ rx := Rx, tx := Tx, final_state := FState }, #{ state := {_, _, Buf} }} -> {ok, #{ rx := Rx, tx := Tx, final_state := FState }, #{ state := {_, _, Buf} }} ->
{ok, Pid} = enoise_connection:start_link(TcpSock, Rx, Tx, self(), {Active, Buf}), case enoise_connection:start_link(TcpSock, Rx, Tx, self(), {Active, Buf}) of
{ok, #enoise{ pid = Pid }, FState}; {ok, Pid} -> {ok, #enoise{ pid = Pid }, FState};
Err = {error, _} -> Err
end;
Err = {error, _} -> Err = {error, _} ->
Err Err
end; end;

View File

@ -37,7 +37,8 @@ start_link(TcpSock, Rx, Tx, Owner, {Active0, Buf}) ->
tcp_sock = TcpSock, active = Active }, tcp_sock = TcpSock, active = Active },
case gen_server:start_link(?MODULE, [State], []) of case gen_server:start_link(?MODULE, [State], []) of
{ok, Pid} -> {ok, Pid} ->
ok = gen_tcp:controlling_process(TcpSock, Pid), case gen_tcp:controlling_process(TcpSock, Pid) of
ok ->
%% Changing controlling process require a bit of %% Changing controlling process require a bit of
%% fiddling with already received and delivered content... %% fiddling with already received and delivered content...
[ Pid ! {tcp, TcpSock, Buf} || Buf /= <<>> ], [ Pid ! {tcp, TcpSock, Buf} || Buf /= <<>> ],
@ -45,6 +46,9 @@ start_link(TcpSock, Rx, Tx, Owner, {Active0, Buf}) ->
{ok, Pid}; {ok, Pid};
Err = {error, _} -> Err = {error, _} ->
Err Err
end;
Err = {error, _} ->
Err
end. end.
send(Noise, Data) -> send(Noise, Data) ->