Open endragor opened 7 years ago
That's not how the SafeDisconn
flag was designed to work in the first place. I don't think an error should be raised when an "orderly shutdown" occurs, because that's not an error.
At least explaining the meaning of SafeDisconn
in the doc would be nice. My expectation was that recv() without SafeDisconn
would never successfully complete without reading any data. Now it turns out SafeDisconn
for recv() is somewhat useless, because you have to handle 0-byte read in either case. At the same time send() will always fail on disconnect without SafeDisconn
, even if the other side performed an orderly shutdown.
Now it turns out SafeDisconn for recv() is somewhat useless, because you have to handle 0-byte read in either case.
The SafeDisconn
flag is incredibly useful. It ensures that you can handle simply handle the case where recv
returns 0 bytes, without worrying about Connection Reset by Peer and other such errors.
What I meant is that there seems to be no use case when you want not to use it. So in the end it's useless to have a flag that has a single reasonable state.
What about the case when you want to distinguish between an orderly shutdown and an error?
When do you think that happens? Usually how you handle disconnection is bound to the protocol. If the other side disconnected in the middle of conversation, that's a bad thing, regardless of how it disconnected. And if it disconnected after sending/receiving all the data you wanted, it doesn't matter again how it did that (you will not know it actually, because you've likely closed the socket on your side and not calling send()/recv()).
I've looked at Java APIs, both synchronous and async, and they don't seem to make that distinguishment - read() either completes successfully or doesn't. That design makes sense to me, and that means that none of Java applications in the world needed to make the distinguishment.
In general I try not to abstract the operating system too much if I can help it. The POSIX APIs deemed it appropriate to have separate errors for non-orderly shutdowns and so we do as well.
This issue has been automatically marked as stale because it has not had recent activity. If you think it is still a valid issue, write a comment below; otherwise it will be closed. Thank you for your contributions.
On *nix systems (haven't checked Windows) recv() and recvInto() procs consider that disconnection happens only when recv syscall errors out. But actually, quoting the man:
So they should actually also handle 0 return value as disconnection and error out if SafeDisconn is not present.