Skip to content
Closed
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 @@ -187,17 +187,24 @@ private async Task ProcessReceives()
{
// Resolve `input` PipeWriter via the IDuplexPipe interface prior to loop start for performance.
var input = Input;

Memory<byte> buffer = default;
if (!_waitForData)
{
// Ensure we have some reasonable amount of buffer space to start.
buffer = input.GetMemory(MinAllocBufferSize);
}

while (true)
{
if (_waitForData)
{
// Wait for data before allocating a buffer.
await _receiver.WaitForDataAsync();
// Data ready, allocate some memory to receive it.
buffer = input.GetMemory(MinAllocBufferSize);
}

// Ensure we have some reasonable amount of buffer space
var buffer = input.GetMemory(MinAllocBufferSize);

var bytesReceived = await _receiver.ReceiveAsync(buffer);

if (bytesReceived == 0)
Expand All @@ -209,7 +216,18 @@ private async Task ProcessReceives()

input.Advance(bytesReceived);

var flushTask = input.FlushAsync();
var flushTask = input.FlushAsync(isMoreData: !_waitForData);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benaadams @davidfowl Any chance we're getting the isMoreData: API in .NET 5?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No; too soon

if (!_waitForData)
{
if (buffer.Length - bytesReceived >= MinAllocBufferSize)
{
buffer = buffer.Slice(bytesReceived);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The skipping of the call to GetMemory() doesn't even look like it should be allowed by the PipeWriter. Is this critical for perf?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its what the api would allow

}
else
{
buffer = input.GetMemory(MinAllocBufferSize);
}
}

var paused = !flushTask.IsCompleted;

Expand Down