Handle errors in start_link (tcp_closed)
This commit is contained in:
parent
41b8efd201
commit
fc510c07a1
@ -237,8 +237,10 @@ tcp_handshake(TcpSock, Role, Options) ->
|
||||
|
||||
case handshake(Options, Role, ComState) of
|
||||
{ok, #{ rx := Rx, tx := Tx, final_state := FState }, #{ state := {_, _, Buf} }} ->
|
||||
{ok, Pid} = enoise_connection:start_link(TcpSock, Rx, Tx, self(), {Active, Buf}),
|
||||
{ok, #enoise{ pid = Pid }, FState};
|
||||
case enoise_connection:start_link(TcpSock, Rx, Tx, self(), {Active, Buf}) of
|
||||
{ok, Pid} -> {ok, #enoise{ pid = Pid }, FState};
|
||||
Err = {error, _} -> Err
|
||||
end;
|
||||
Err = {error, _} ->
|
||||
Err
|
||||
end;
|
||||
|
@ -37,12 +37,16 @@ start_link(TcpSock, Rx, Tx, Owner, {Active0, Buf}) ->
|
||||
tcp_sock = TcpSock, active = Active },
|
||||
case gen_server:start_link(?MODULE, [State], []) of
|
||||
{ok, Pid} ->
|
||||
ok = gen_tcp:controlling_process(TcpSock, Pid),
|
||||
%% Changing controlling process require a bit of
|
||||
%% fiddling with already received and delivered content...
|
||||
[ Pid ! {tcp, TcpSock, Buf} || Buf /= <<>> ],
|
||||
flush_tcp(Pid, TcpSock),
|
||||
{ok, Pid};
|
||||
case gen_tcp:controlling_process(TcpSock, Pid) of
|
||||
ok ->
|
||||
%% Changing controlling process require a bit of
|
||||
%% fiddling with already received and delivered content...
|
||||
[ Pid ! {tcp, TcpSock, Buf} || Buf /= <<>> ],
|
||||
flush_tcp(Pid, TcpSock),
|
||||
{ok, Pid};
|
||||
Err = {error, _} ->
|
||||
Err
|
||||
end;
|
||||
Err = {error, _} ->
|
||||
Err
|
||||
end.
|
||||
|
Loading…
x
Reference in New Issue
Block a user