Optimize zero-byte receives on ManagedWebSocket (#87329)
authorStephen Toub <stoub@microsoft.com>
Sun, 11 Jun 2023 15:10:18 +0000 (11:10 -0400)
committerGitHub <noreply@github.com>
Sun, 11 Jun 2023 15:10:18 +0000 (11:10 -0400)
commit63a945827a2ecb204436670d42609e5bd5542c9a
tree70b081545a5264679ae4dda74b1a96422fbbf2de
parent362678a6c7d45f9a49c4aaa946701f791c56b484
Optimize zero-byte receives on ManagedWebSocket (#87329)

Today you can perform a zero-byte receive on ManagedWebSocket, but doing so still issues a request to the underlying stream with the receive header buffer.  That in turn can cause the underlying stream to rent and/or pin a buffer.  By special-casing zero-byte reads, we can take advantage of any special-casing in the base stream, and hopefully make it so that when the actual read is performed, the data necessary to satisfy it synchronously is already available.
src/libraries/System.Net.WebSockets/src/System/Net/WebSockets/ManagedWebSocket.cs