[erlang-questions] monitor sockets

Roberto Ostinelli roberto@REDACTED
Sun Mar 20 18:29:26 CET 2011


2011/3/20 Steve Vinoski <vinoski@REDACTED>

> I use this feature and from what I've seen it works well. Can you
> supply details or code for the kinds of problems you see?
>
> In my embedded Yaws system we use TCP offload sockets, and I have a
> special linked-in driver that interacts with our hardware to open
> them. When you open an Erlang socket by supplying your own file
> descriptor, as I do for this TCP offload case, the VM doesn't close
> the socket file descriptor when its owning process dies as it will for
> regular sockets. It instead assumes that since you opened the fd
> separately, you'll take care of closing it separately too. I use
> socket linking to ensure our underlying offload socket fd also gets
> closed.
>
> --steve
>

hi steve,

i'm using the socket in {active, once} mode, and after having read headers
and body i proceed to treat a request and i end up in a loop which controls
the logic handler.

you can see the loop here:
https://github.com/ostinelli/misultin/blob/master/src/misultin_http.erl#L297

i tried linking to the port before entering this loop in the call_mfa/2
function, i.e.

link(Sock)

however the receive... end loop in the socket_loop/3 function never does
receive a tcp_closed message.

if i insert, as yurii has suggested, at the beginning of the socket_loop/3
function:
+  misultin_socket:setopts(Sock, [{active, once}], SocketMode)

then i do get the {tcp_closed, <Port>} message. before adopting this
technique, though, i wanted to see which other possibilities i have.

thank you,

r.


More information about the erlang-questions mailing list