Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,11 @@ private int ReadResponseContent(HttpResponseMessage response, Span<byte> buffer)
totalBytesRead += bytesRead;
_responseDataPayloadRemaining -= bytesRead;
buffer = buffer.Slice(bytesRead);

if (_responseDataPayloadRemaining == 0)
{
break;
}
}
}

Expand Down Expand Up @@ -1085,6 +1090,11 @@ private async ValueTask<int> ReadResponseContentAsync(HttpResponseMessage respon
totalBytesRead += bytesRead;
_responseDataPayloadRemaining -= bytesRead;
buffer = buffer.Slice(bytesRead);

if (_responseDataPayloadRemaining == 0)
{
break;
}
}
}

Expand Down
55 changes: 55 additions & 0 deletions src/libraries/System.Net.Quic/tests/FunctionalTests/MsQuicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Net.Security;
using System.Net.Sockets;
using System.Security.Authentication;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -801,5 +802,59 @@ await Task.Run(async () =>
await Assert.ThrowsAsync<QuicOperationAbortedException>(() => serverStream.ReadAsync(buffer).AsTask());
}).WaitAsync(TimeSpan.FromMilliseconds(PassingTestTimeoutMilliseconds));
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public async Task BigWrite_SmallRead_Success(bool closeWithData)
{
const int size = 100;
(QuicConnection clientConnection, QuicConnection serverConnection) = await CreateConnectedQuicConnection();
using (clientConnection)
using (serverConnection)
{
byte[] buffer = new byte[1] { 42 };

QuicStream clientStream = clientConnection.OpenBidirectionalStream();
Task<QuicStream> t = serverConnection.AcceptStreamAsync().AsTask();
await TaskTimeoutExtensions.WhenAllOrAnyFailed(clientStream.WriteAsync(buffer).AsTask(), t, PassingTestTimeoutMilliseconds);
QuicStream serverStream = t.Result;
Assert.Equal(1, await serverStream.ReadAsync(buffer));

// streams are new established and in good shape.
using (clientStream)
using (serverStream)
{
byte[] expected = RandomNumberGenerator.GetBytes(size);
byte[] actual = new byte[size];

// should be small enough to fit.
await serverStream.WriteAsync(expected, closeWithData);

// Add delay to have chance to receive the 100b block before ReadAsync starts.
await Task.Delay(10);
int remaining = size;
int readLength;
while (remaining > 0)
{
readLength = await clientStream.ReadAsync(new Memory<byte>(actual, size - remaining, 1));
Assert.Equal(1, readLength);
remaining--;
}

Assert.Equal(expected, actual);

if (!closeWithData)
{
serverStream.Shutdown();
}

readLength = await clientStream.ReadAsync(actual);
Assert.Equal(0, readLength);

Assert.Equal(expected, actual);
}
}
}
}
}