[erlang-questions] EPIPE and TCP sockets

Per Hedeland per@REDACTED
Fri Oct 12 00:44:17 CEST 2007


Tony Garnock-Jones <tonyg@REDACTED> wrote:
>
>If I understand correctly, the BSD sockets interface to TCP lets you 
>know when a TCP socket is closed with outbound data unacknowledged, by 
>sending the sender SIGPIPE (or returning EPIPE if SIGPIPE is blocked).

Hm, I don't think that's correct - AFAIK SIGPIPE/EPIPE happens only if
you try to write more data to a socket when the other end is considered
to be closed (either due to receiving FIN or RST, or due to
retransmission timeout).

Closing the socket with unack'ed data normally doesn't do anything in
particular, the close() returns immediately but the kernel holds on to
the data and tries to (re)transmit it according to the standard TCP
logic, and you won't be told if it fails.

You can change the latter behaviour via the SO_LINGER socket option, to
have the close() block until the data is ack'ed or failure/timeout. To
quote an earlier message here: "This is actually available for gen_tcp
too, via the undocumented 'linger' option - whether it really works I
don't know." And thinking about it, I'm not sure *how* it will/would
work - there would need to be a "non-blocking blocking on close()"
(maybe there is) to avoid having the whole runtime block...

--Per Hedeland



More information about the erlang-questions mailing list