Created
December 16, 2017 21:13
-
-
Save essen/599a9652e5c3db591ab2198278722a6f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
do_get_remote_pid_tcp(Socket) when is_port(Socket) → | |
do_get_remote_pid_tcp(inet:sockname(Socket)); | |
do_get_remote_pid_tcp(SockName) → | |
AllPorts = [{P, erlang:port_info(P)} || P ← erlang:ports()], | |
[Pid] = [ | |
proplists:get_value(connected, I) | |
|| {P, I} ← AllPorts, | |
proplists:get_value(name, I) ≡ "tcp_inet", | |
inet:peername(P) ≡ SockName], | |
Pid. | |
-include_lib("ssl/src/ssl_connection.hrl"). | |
do_get_remote_pid_tls(Socket) → | |
%% This gives us the pid of the sslsocket process. | |
%% We must introspect this process in order to retrieve the connection pid. | |
TLSPid = do_get_remote_pid_tcp(ssl:sockname(Socket)), | |
{_, #state{user_application={_, UserPid}}} = sys:get_state(TLSPid), | |
UserPid. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment