Don't trust inet:getopts to succeed
This commit is contained in:
parent
7347906f29
commit
4c436e395d
@ -234,17 +234,9 @@ do_step_handshake(HState, Data) ->
|
|||||||
tcp_handshake(TcpSock, Role, Options) ->
|
tcp_handshake(TcpSock, Role, Options) ->
|
||||||
case check_gen_tcp(TcpSock) of
|
case check_gen_tcp(TcpSock) of
|
||||||
ok ->
|
ok ->
|
||||||
{ok, [{active, Active}]} = inet:getopts(TcpSock, [active]),
|
case inet:getopts(TcpSock, [active]) of
|
||||||
ComState = #{ recv_msg => fun gen_tcp_rcv_msg/2,
|
{ok, [{active, Active}]} ->
|
||||||
send_msg => fun gen_tcp_snd_msg/2,
|
do_tcp_handshake(Options, Role, TcpSock, Active);
|
||||||
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
|
|
||||||
{ok, Pid} -> {ok, #enoise{ pid = Pid }, FState};
|
|
||||||
Err = {error, _} -> Err
|
|
||||||
end;
|
|
||||||
Err = {error, _} ->
|
Err = {error, _} ->
|
||||||
Err
|
Err
|
||||||
end;
|
end;
|
||||||
@ -252,6 +244,20 @@ tcp_handshake(TcpSock, Role, Options) ->
|
|||||||
Err
|
Err
|
||||||
end.
|
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
|
||||||
|
{ok, Pid} -> {ok, #enoise{ pid = Pid }, FState};
|
||||||
|
Err = {error, _} -> Err
|
||||||
|
end;
|
||||||
|
Err = {error, _} ->
|
||||||
|
Err
|
||||||
|
end.
|
||||||
|
|
||||||
create_hstate(Options, Role) ->
|
create_hstate(Options, Role) ->
|
||||||
Prologue = proplists:get_value(prologue, Options, <<>>),
|
Prologue = proplists:get_value(prologue, Options, <<>>),
|
||||||
NoiseProtocol0 = proplists:get_value(noise, Options),
|
NoiseProtocol0 = proplists:get_value(noise, Options),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user