Skip to content

Commit f25f432

Browse files
guhetiermtfriesen
andauthored
[CP] Persists the virtual buffer size when switching to app owned buffers #5690 (#5719)
## Description When an endpoint receives a new stream indication, it can provide some receive buffers inline to convert the stream to app-owned buffer mode. When doing so, the receive buffer struct of the stream is reinitialized, and the virtual buffer length (which correspond to the stream receive window) was set to zero. This is incorrect since we introduced the "more buffer needed" notification and the receive window is no longer tied to the amount of buffer provided. This would result in a receive failure with data received outside of the virtual size. When converting the receive buffer to app-buffer mode, the virtual size is now preserved. Fixes #5672. ## Testing Test not backported as they rely on changes present only in main ## Documentation Clarify documentation about the app provided receive buffer ownership. --------- Co-authored-by: Michael Friesen <[email protected]>
1 parent b25db06 commit f25f432

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

docs/Streams.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ There is no guarantee the `QUIC_BUFFER`s indicated in a receive notification wil
167167

168168
The application is responsible for tracking the amount of data received and when a buffer it provided has been fully used.
169169
The application regains full ownership of a buffer after it get a receive notification for all bytes in the buffer and accept them by calling [StreamReceiveComplete](api/StreamReceiveComplete.md).
170+
MsQuic will not re-use a buffer for subsequent receives once it has been fully written, unless the app submits the same buffer again.
170171
If the application accepts all the buffer's bytes **inline** from the receive notification, by returning `QUIC_STATUS_SUCCESS` and setting `TotalBufferLength` appropriately,
171172
it can free or reuse the buffer while in the notification handler.
172173

src/core/stream.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,16 @@ QuicStreamSwitchToAppOwnedBuffers(
977977
)
978978
{
979979
//
980-
// Reset the current receive buffer and preallocated chunk.
980+
// Preserve the initial receive window size: it should not have changed
981+
// since the stream's creation.
982+
//
983+
const uint32_t InitialControlFlow = Stream->RecvBuffer.VirtualBufferLength;
984+
CXPLAT_DBG_ASSERT(
985+
InitialControlFlow == Stream->Connection->Settings.StreamRecvWindowBidiRemoteDefault ||
986+
InitialControlFlow == Stream->Connection->Settings.StreamRecvWindowUnidiDefault);
987+
988+
//
989+
// Reset the current receive buffer
981990
//
982991
QuicRecvBufferUninitialize(&Stream->RecvBuffer);
983992
if (Stream->RecvBuffer.PreallocatedChunk) {
@@ -991,7 +1000,7 @@ QuicStreamSwitchToAppOwnedBuffers(
9911000
(void)QuicRecvBufferInitialize(
9921001
&Stream->RecvBuffer,
9931002
0,
994-
0,
1003+
InitialControlFlow,
9951004
QUIC_RECV_BUF_MODE_APP_OWNED,
9961005
NULL);
9971006
Stream->Flags.UseAppOwnedRecvBuffers = TRUE;

0 commit comments

Comments
 (0)