Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Kaz Kylheku Newsgroups: comp.os.linux.development.apps Subject: Re: EOF, close(), shutdown(), on POSIX sockets Date: Thu, 12 Jan 2012 20:04:29 +0000 (UTC) Organization: A noiseless patient Spider Lines: 27 Message-ID: <20120112115830.10@kylheku.com> References: <1br4zdh37t.fsf@pfeifferfamily.net> <1bfwfkr8w0.fsf@pfeifferfamily.net> Injection-Date: Thu, 12 Jan 2012 20:04:29 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="UCk3K/YilCUd19+i749f3A"; logging-data="1449"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+xUXO/QmmrWWqSjzzYH4V14GydN4l5wbQ=" User-Agent: slrn/pre1.0.0-18 (Linux) Cancel-Lock: sha1:2AolzSdYM2kgw+J5eFWKtO9Zaqo= Xref: x330-a1.tempe.blueboxinc.net comp.os.linux.development.apps:387 On 2012-01-12, Joe Pfeiffer wrote: > Andrei Voropaev writes: >> Of course, many protocols allow sending of explicit notification to the peer >> when more data is not going to be accepted. But even in this case you >> should be ready to handle EPIPE error. > > You seem to be addressing the question of when the transmitter can know > the receiver has shut down. My experience has been that when the > *transmitter* has shut down, the receiver may wait an arbitrary amount > of time in a read() before finally returning a 0. Only because of network issues. When the transmitter has sealed that direction by shutting it down, it means that there is a queue of packets on the transmit side which has to drain. Only the last segment will carry the FIN flag indicating "I am the last". The network can be disrupted in the meanwhile. (Basically no byte that is sent by the transmitter will reach the receiver in a guaranteed time, and that includes the FIN flag.) On a fast, reliable network, you should not be seeing delays in read when the other side has shut down the connection. If the transmitting host crashes, or there is a long-term network outage or something else (e.g NAT mapping entry expiring, so you permanently lose the virtual circuit with no notification), that is different.