fix(exproto): get peername after esockd_wait/1
This commit is contained in:
parent
c878c73395
commit
31cbd66f61
|
@ -164,12 +164,21 @@ init(ConnInfo = #{socktype := Socktype,
|
||||||
try_dispatch(on_socket_created, wrap(Req), Channel).
|
try_dispatch(on_socket_created, wrap(Req), Channel).
|
||||||
|
|
||||||
%% @private
|
%% @private
|
||||||
peercert(nossl, ConnInfo) ->
|
peercert(NoSsl, ConnInfo) when NoSsl == nossl;
|
||||||
|
NoSsl == undefined ->
|
||||||
ConnInfo;
|
ConnInfo;
|
||||||
peercert(Peercert, ConnInfo) ->
|
peercert(Peercert, ConnInfo) ->
|
||||||
ConnInfo#{peercert =>
|
Fn = fun(_, V) -> V =/= undefined end,
|
||||||
#{cn => esockd_peercert:common_name(Peercert),
|
Infos = maps:filter(Fn,
|
||||||
dn => esockd_peercert:subject(Peercert)}}.
|
#{cn => esockd_peercert:common_name(Peercert),
|
||||||
|
dn => esockd_peercert:subject(Peercert)}
|
||||||
|
),
|
||||||
|
case maps:size(Infos) of
|
||||||
|
0 ->
|
||||||
|
ConnInfo;
|
||||||
|
_ ->
|
||||||
|
ConnInfo#{peercert => Infos}
|
||||||
|
end.
|
||||||
|
|
||||||
%% @private
|
%% @private
|
||||||
socktype(tcp) -> 'TCP';
|
socktype(tcp) -> 'TCP';
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
]).
|
]).
|
||||||
|
|
||||||
%% Callback
|
%% Callback
|
||||||
-export([init/4]).
|
-export([init/3]).
|
||||||
|
|
||||||
%% Sys callbacks
|
%% Sys callbacks
|
||||||
-export([ system_continue/3
|
-export([ system_continue/3
|
||||||
|
@ -100,19 +100,15 @@
|
||||||
]}).
|
]}).
|
||||||
|
|
||||||
%% udp
|
%% udp
|
||||||
start_link(Socket = {udp, _SockPid, _Sock}, Peername, Options) ->
|
start_link(Socket = {udp, _SockPid, _Sock}, _Peername, Options) ->
|
||||||
Args = [self(), Socket, Peername, Options],
|
Args = [self(), Socket, Options],
|
||||||
{ok, proc_lib:spawn_link(?MODULE, init, Args)};
|
{ok, proc_lib:spawn_link(?MODULE, init, Args)};
|
||||||
|
|
||||||
%% tcp/ssl/dtls
|
%% tcp/ssl/dtls
|
||||||
start_link(esockd_transport, Sock, Options) ->
|
start_link(esockd_transport, Sock, Options) ->
|
||||||
Socket = {esockd_transport, Sock},
|
Socket = {esockd_transport, Sock},
|
||||||
case esockd_transport:peername(Sock) of
|
Args = [self(), Socket, Options],
|
||||||
{ok, Peername} ->
|
{ok, proc_lib:spawn_link(?MODULE, init, Args)}.
|
||||||
Args = [self(), Socket, Peername, Options],
|
|
||||||
{ok, proc_lib:spawn_link(?MODULE, init, Args)};
|
|
||||||
R = {error, _} -> R
|
|
||||||
end.
|
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% API
|
%% API
|
||||||
|
@ -227,9 +223,10 @@ send(Data, #state{socket = {esockd_transport, Sock}}) ->
|
||||||
-define(DEFAULT_IDLE_TIMEOUT, 30000).
|
-define(DEFAULT_IDLE_TIMEOUT, 30000).
|
||||||
-define(DEFAULT_OOM_POLICY, #{max_heap_size => 4194304,message_queue_len => 32000}).
|
-define(DEFAULT_OOM_POLICY, #{max_heap_size => 4194304,message_queue_len => 32000}).
|
||||||
|
|
||||||
init(Parent, WrappedSock, Peername, Options) ->
|
init(Parent, WrappedSock, Options) ->
|
||||||
case esockd_wait(WrappedSock) of
|
case esockd_wait(WrappedSock) of
|
||||||
{ok, NWrappedSock} ->
|
{ok, NWrappedSock} ->
|
||||||
|
{ok, Peername} = esockd_ensure_ok_or_exit(peername, NWrappedSock),
|
||||||
run_loop(Parent, init_state(NWrappedSock, Peername, Options));
|
run_loop(Parent, init_state(NWrappedSock, Peername, Options));
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
ok = esockd_close(WrappedSock),
|
ok = esockd_close(WrappedSock),
|
||||||
|
|
Loading…
Reference in New Issue