Skip to content

Commit f73c11e

Browse files
Detailed docs on Socket.Read* and NetworkStream.Receive* return values (#10983)
The wording is mostly borrowed from the `Stream.Read*` variants but saying `the peer socket performed a graceful shutdown` instead of `end of the stream has been reached`, which describes the EOF reason more specifically in this case. --------- Co-authored-by: Genevieve Warren <[email protected]>
1 parent bf22adb commit f73c11e

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
lines changed

xml/System.Net.Sockets/NetworkStream.xml

+6-6
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,7 @@ The Close method frees both unmanaged and managed resources associated with the
11071107
<Docs>
11081108
<param name="asyncResult">An <see cref="T:System.IAsyncResult" /> that represents an asynchronous call.</param>
11091109
<summary>Handles the end of an asynchronous read.</summary>
1110-
<returns>The number of bytes read from the <see cref="T:System.Net.Sockets.NetworkStream" />.</returns>
1110+
<returns>The number of bytes read from the <see cref="T:System.Net.Sockets.NetworkStream" />, between zero (0) and the number of bytes requested. The method returns zero (0) only if zero bytes were requested or if no more bytes are available because the peer socket performed a graceful shutdown. If zero bytes are requested, read operations might complete immediately or might not complete until at least one byte is available (but without consuming any data).</returns>
11111111
<remarks>
11121112
<format type="text/markdown"><![CDATA[
11131113
@@ -1466,7 +1466,7 @@ The Close method frees both unmanaged and managed resources associated with the
14661466
<Docs>
14671467
<param name="buffer">A region of memory to store data read from the <see cref="T:System.Net.Sockets.NetworkStream" />.</param>
14681468
<summary>Reads data from the <see cref="T:System.Net.Sockets.NetworkStream" /> and stores it to a span of bytes in memory.</summary>
1469-
<returns>The number of bytes read from the <see cref="T:System.Net.Sockets.NetworkStream" />.</returns>
1469+
<returns>The total number of bytes read into the buffer, between zero (0) and the length of the buffer. The method returns zero (0) only if zero bytes were requested or if no more bytes are available because the peer socket performed a graceful shutdown.</returns>
14701470
<remarks>
14711471
<format type="text/markdown"><![CDATA[
14721472
@@ -1543,7 +1543,7 @@ There is a failure reading from the network.</exception>
15431543
<param name="size">The number of bytes to read from the <see cref="T:System.Net.Sockets.NetworkStream" />.</param>
15441544
<param name="count">The number of bytes to read from the <see cref="T:System.Net.Sockets.NetworkStream" />.</param>
15451545
<summary>Reads data from the <see cref="T:System.Net.Sockets.NetworkStream" /> and stores it to a byte array.</summary>
1546-
<returns>The number of bytes read from the <see cref="T:System.Net.Sockets.NetworkStream" />.</returns>
1546+
<returns>The total number of bytes read into the buffer between zero (0) and the requested count. The method returns zero (0) only if zero bytes were requested or if no more bytes are available because the peer socket performed a graceful shutdown.</returns>
15471547
<remarks>
15481548
<format type="text/markdown"><![CDATA[
15491549
@@ -1695,7 +1695,7 @@ There is a failure reading from the network.</exception>
16951695
<param name="buffer">The buffer to write the data to.</param>
16961696
<param name="cancellationToken">The token to monitor for cancellation requests.</param>
16971697
<summary>Reads data from the <see cref="T:System.Net.Sockets.NetworkStream" /> and stores it in a byte memory range as an asynchronous operation.</summary>
1698-
<returns>A <see cref="T:System.Threading.Tasks.ValueTask`1" /> that represents the asynchronous read operation. The value of its <see cref="P:System.Threading.Tasks.ValueTask`1.Result" /> property contains the total number of bytes read into <paramref name="buffer" />.</returns>
1698+
<returns>A <see cref="T:System.Threading.Tasks.ValueTask`1" /> that represents the asynchronous read operation. The value of its <see cref="P:System.Threading.Tasks.ValueTask`1.Result" /> property contains the total number of bytes read into <paramref name="buffer" /> between zero (0) and the number of bytes requested. The result value is zero (0) only if zero bytes were requested or if no more bytes are available because the peer socket performed a graceful shutdown. If zero bytes are requested, read operations may complete immediately or may not complete until at least one byte is available (but without consuming any data).</returns>
16991699
<remarks>
17001700
<format type="text/markdown"><![CDATA[
17011701
@@ -1766,7 +1766,7 @@ There is a failure reading from the network.</exception>
17661766
<param name="count">The number of bytes to read from the <see cref="T:System.Net.Sockets.NetworkStream" />.</param>
17671767
<param name="cancellationToken">The token to monitor for cancellation requests.</param>
17681768
<summary>Reads data from the <see cref="T:System.Net.Sockets.NetworkStream" /> and stores it to a specified range of a byte array as an asynchronous operation.</summary>
1769-
<returns>A task that represents the asynchronous read operation. The value of its <see cref="P:System.Threading.Tasks.Task`1.Result" /> property contains the total number of bytes read into <paramref name="buffer" />.</returns>
1769+
<returns>A task that represents the asynchronous read operation. The value of its <see cref="P:System.Threading.Tasks.Task`1.Result" /> property contains the total number of bytes read into <paramref name="buffer" /> between zero (0) and the number of bytes requested. The result value is zero (0) only if zero bytes were requested or if no more bytes are available because the peer socket performed a graceful shutdown. If zero bytes are requested, read operations may complete immediately or may not complete until at least one byte is available (but without consuming any data).</returns>
17701770
<remarks>
17711771
<format type="text/markdown"><![CDATA[
17721772
@@ -1821,7 +1821,7 @@ There is a failure reading from the network.</exception>
18211821
<Parameters />
18221822
<Docs>
18231823
<summary>Reads a byte from the <see cref="T:System.Net.Sockets.NetworkStream" /> and advances the position within the stream by one byte, or returns -1 if at the end of the stream.</summary>
1824-
<returns>The unsigned byte cast to an <see cref="T:System.Int32" />, or -1 if at the end of the stream.</returns>
1824+
<returns>The unsigned byte cast to an <see cref="T:System.Int32" />, or -1 if at the end of the stream because the peer socket performed a graceful shutdown.</returns>
18251825
<remarks>
18261826
<format type="text/markdown"><![CDATA[
18271827

0 commit comments

Comments
 (0)