[erlang-questions] Monitor sockets

Loïc Hoguin <>
Mon Jan 14 15:51:45 CET 2013


Hello,

It is currently not possible to only listen for tcp_closed events on a 
socket through the current interface. Sure you can link with a gen_tcp 
socket, because the socket is a port and you can link to these, but you 
can't with ssl because the socket is an opaque type and the port is deep 
inside it (or at least not easily).

We could have one of two solutions to know when a socket closed. I would 
like to implement whichever is the best. Please tell me and I'll send a 
patch.

1) Add gen_tcp:link/1, gen_tcp:unlink/1, ssl:link/1 and ssl:unlink/1 to 
link/unlink with the port that manages the socket

This would likely be the easiest, but requires trapping exits and I 
would like to avoid doing that, because the user's code may not want that.

2) Add {inet,ssl}:setopts([{active, once_closed_only}]), would only 
listen for and send the {tcp,ssl}_closed messages, option name could be 
improved

This would be perhaps harder to write, but would be much easier to work 
with, as this would be just a message to receive, and a message we 
already know.

Would OTP team be interested in such a feature?

-- 
Loïc Hoguin
Erlang Cowboy
Nine Nines
http://ninenines.eu



More information about the erlang-questions mailing list