-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Update comment on return value of NetworkStream.Read* variants #10960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Fixes #10925. Mentions that returns 0 when socket was closed.
Tagging subscribers to this area: @dotnet/ncl |
Learn Build status updates of commit 04b0287: ✅ Validation status: passed
For more details, please refer to the build report. For any questions, please:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment in the code qouted in #10925 is wrong.
When the receiver socket is closed an exception will be thrown (ODE on abortive close - or SocketException(SocketError.Shutdown)
if graceful shutdown of receives has been initiated.).
0
bytes will be received when the peer has initiated a graceful termination of writes (either by calling Shutdown(Send / Both)
or by calling Close(0)
, which means compliance with base class Stream.Read*
EOF spec:
The total number of bytes read into the buffer. This can be less than the size of the buffer if that many bytes are not currently available, or zero (0) if the buffer's length is zero or the end of the stream has been reached.
When the the peer socket is aborted and sent RST, an exception SocketException(ConnectionReset)
will be thrown.
So IMO the docs should be either copypaste Stream.Read
content, or slightly augment it, eg.:
The total number of bytes read into the buffer. This can be less than the size of the buffer if that many bytes are not currently available, or zero (0) if the buffer's length is zero or the end of the stream has been reached, that is the peer socket has initiated graceful shutdown of writes.
Edit: My comments above are describing Socket
behavior when it comes to exceptions; whatever Exception
is thrown by the underlying socket is wrapped into IOException
in NetworkStream
. When a NetworkStream
is disposed/closed directly, ObjectDisposedException
is thrown.
Both suggested answers are correct, but they do not answer the user's questions about the method, but simply refer to look for information in other sources When we come to look at the instructions, we want to see information about how the methods work. If we simply copy from the Read method, the users will find out that this method works a little differently from other streams only by making a bug in their code. I went to the documentation to find out exactly the differences in the behavior of this method:
Sounds much better and describes behaviour And of course, this is just my opinion. Perhaps my point of view does not coincide with the point of view of the majority |
This is true, but on the other hand, this description is .NET-specific, while the description of the peer's behavior should be worded in a platform-agnostic manner since the peer socket isn't necessarily created by .NET. At the platform level there is no I agree we may improve our socket docs to describe various socket/TCP termination behaviors and how .NET methods map to lower-level behaviors, but IMO the TLDR: I'm struggling to find a wording that is short, specific and platform-agnostic at the same time. (But I'm open for suggestions!) |
Closing this in favor of #10983. |
Fixes #10925.
Mentions that returns 0 when socket was closed.