[erlang-questions] No message sent when closing socket

Christoph Dornheim cd5@REDACTED
Wed Feb 28 20:02:03 CET 2007


Hi, 

I have an application where a TCP-connection should be terminated by any process
having its socket available. The socket S is accepted by a server socket running
in active mode: 

gen_tcp:listen(1234, [list, {packet, line}, {active, true}])

The controlling process receives the incoming data from S as expected. The
receive clause lets the process terminate normally when the message
{tcp_closed,S} is received.

I expected that gen_tcp:close(S) sends this message to the controlling process,
but unfortunately, no message is sent (although the socket got closed, confirmed
by inet:i() ).  

Did I miss something in the gen_tcp documentation? Alternatively, I can use
gen_tcp:shutdown(S, read_write) which works fine and sends the close message.

I'm wondering why gen_tcp:close does not inform the controlling process that its
socket is closed. Is it generally a better way to close a socket by using
gen_tcp:shutdown instead of gen_tcp:close?


Best regards,

Christoph




More information about the erlang-questions mailing list