[erlang-questions] fd and controlling process

Salikhov Dinislam Dinislam.Salikhov@REDACTED
Mon Feb 6 16:18:42 CET 2017


 > 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 
>> <Dinislam.Salikhov@REDACTED 
>> <mailto:Dinislam.Salikhov@REDACTED>> 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:
>>
>> http://erlang.org/doc/man/gen_tcp.html
>>
>> --steve
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170206/ff746f92/attachment.htm>


More information about the erlang-questions mailing list