fd and controlling process

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

fd and controlling process

Salikhov Dinislam
Hi!

I have a Unix file descriptor of Erlang VM process.
I know that it is a TCP socket in ESTABLISHED state.
Is there a way to receive an Erlang port of the socket?
Is there a way to receive controlling process of the socket?

Salikhov Dinislam
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: fd and controlling process

Steve Vinoski-2


On Mon, Feb 6, 2017 at 8:18 AM, Salikhov Dinislam <[hidden email]> wrote:
Hi!

I have a Unix file descriptor of Erlang VM process.
I know that it is a TCP socket in ESTABLISHED state.
Is there a way to receive an Erlang port of the socket?
Is there a way to receive controlling process of the socket?

See the {fd, integer() >= 0} option that various gen_tcp functions can take:


--steve

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: fd and controlling process

Salikhov Dinislam
IIUC, {fd, integer() >= 0} allows to use the socket received from socket() C function (or somehow else, but I can't propose another way).

> Is there a way to receive controlling process of the socket?
If we managed to get the port (though I still don't know the way), the controlling process can be obtained as following:
{_, Pid} = erlang:port_info(Port, connected).

On 02/06/2017 04:30 PM, Steve Vinoski wrote:


On Mon, Feb 6, 2017 at 8:18 AM, Salikhov Dinislam <[hidden email]> wrote:
Hi!

I have a Unix file descriptor of Erlang VM process.
I know that it is a TCP socket in ESTABLISHED state.
Is there a way to receive an Erlang port of the socket?
Is there a way to receive controlling process of the socket?

See the {fd, integer() >= 0} option that various gen_tcp functions can take:


--steve


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: fd and controlling process

Salikhov Dinislam
> If we managed to get the port (though I still don't know the way)
Finally, I've managed to do it:
F = fun(P, Acc) -> case catch prim_inet:getfd(P) of {ok, FD} -> [{FD, P} | Acc]; _ -> Acc end end.
L = lists:foldl(F, [], erlang:ports()).
Port = proplists:get_value(MyFD, L).

Pay attention that prim_inet is internal module of VM, so it's usage should be avoided in any production code!

Salikhov Dinislam

On 02/06/2017 05:12 PM, Salikhov Dinislam wrote:
IIUC, {fd, integer() >= 0} allows to use the socket received from socket() C function (or somehow else, but I can't propose another way).

> Is there a way to receive controlling process of the socket?
If we managed to get the port (though I still don't know the way), the controlling process can be obtained as following:
{_, Pid} = erlang:port_info(Port, connected).

On 02/06/2017 04:30 PM, Steve Vinoski wrote:


On Mon, Feb 6, 2017 at 8:18 AM, Salikhov Dinislam <[hidden email]> wrote:
Hi!

I have a Unix file descriptor of Erlang VM process.
I know that it is a TCP socket in ESTABLISHED state.
Is there a way to receive an Erlang port of the socket?
Is there a way to receive controlling process of the socket?

See the {fd, integer() >= 0} option that various gen_tcp functions can take:


--steve



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions