Re: socket write(2) after remote shutdown(2) problem ?

David S. Miller (davem@redhat.com)
Fri, 05 Apr 2002 04:04:51 -0800 (PST)


From: Stelian Pop <stelian.pop@fr.alcove.com>
Date: Fri, 5 Apr 2002 14:00:55 +0200

As you can see, read() doesn't return any error, just 0 to
indicate end-of-file (seems correct interpretation of remote
shutdown here), but it doesn't report any error from the
precedent write... Bug ?

Race, wait a bit, the reset will arrive.

This is a error state in your code, writing when the server expects no
data. Always remember that when you are trying to judge if
whatever socket operation results is valid or invalid.

Since we find out about the reset asynchronously, this is what
happens.

> But all of this is irrelevant. When a server closes and says "send me
> no more data", this implies that the server told the client it doesn't
> want any more data.

Perfectly valid but only if the 'applicative close' has reached the
other end. If it's still queued in TCP buffers, the client may not
have received yet that close... I thought that this was the only
reason that shutdown() existed at all: flush the buffers preparing
an imminent close...

Not a close "in TCP" but a close "in your apps protocol".
As in:

write(socket_fd, "Ok client I have all your data, lets close now")

See? If the server closes without telling the client that, all
bets are off.

Look, your app is buggy, PERIOD. Once you start to write to a closed
socket, sorry the phase of the moon decides what happens to you. Most
of the time you'll be lucky and see an error.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/