Don't trust inet:getopts to succeed

This commit is contained in:
Hans Svensson 2018-05-16 10:42:00 +02:00
parent 7347906f29
commit 4c436e395d

View File

@ -234,11 +234,20 @@ do_step_handshake(HState, Data) ->
tcp_handshake(TcpSock, Role, Options) ->
case check_gen_tcp(TcpSock) of
ok ->
{ok, [{active, Active}]} = inet:getopts(TcpSock, [active]),
case inet:getopts(TcpSock, [active]) of
{ok, [{active, Active}]} ->
do_tcp_handshake(Options, Role, TcpSock, Active);
Err = {error, _} ->
Err
end;
Err = {error, _} ->
Err
end.
do_tcp_handshake(Options, Role, TcpSock, Active) ->
ComState = #{ recv_msg => fun gen_tcp_rcv_msg/2,
send_msg => fun gen_tcp_snd_msg/2,
state => {TcpSock, Active, <<>>} },
case handshake(Options, Role, ComState) of
{ok, #{ rx := Rx, tx := Tx, final_state := FState }, #{ state := {_, _, Buf} }} ->
case enoise_connection:start_link(TcpSock, Rx, Tx, self(), {Active, Buf}) of
@ -247,9 +256,6 @@ tcp_handshake(TcpSock, Role, Options) ->
end;
Err = {error, _} ->
Err
end;
Err = {error, _} ->
Err
end.
create_hstate(Options, Role) ->