}
}
- public override async ValueTask FinishAsync(bool async)
+ public override Task FinishAsync(bool async)
{
// Send 0 byte chunk to indicate end, then final CrLf
HttpConnection connection = GetConnectionOrThrow();
_connection = null;
- await connection.WriteBytesAsync(s_finalChunkBytes, async).ConfigureAwait(false);
+ return connection.WriteBytesAsync(s_finalChunkBytes, async);
}
}
}
return bytesToCopy;
}
- private async ValueTask CopyFromBufferAsync(Stream destination, bool async, int count, CancellationToken cancellationToken)
+ private ValueTask CopyFromBufferAsync(Stream destination, bool async, int count, CancellationToken cancellationToken)
{
Debug.Assert(count <= _readLength - _readOffset);
if (NetEventSource.Log.IsEnabled()) Trace($"Copying {count} bytes to stream.");
+
+ int offset = _readOffset;
+ _readOffset += count;
+
if (async)
{
- await destination.WriteAsync(new ReadOnlyMemory<byte>(_readBuffer, _readOffset, count), cancellationToken).ConfigureAwait(false);
+ return destination.WriteAsync(new ReadOnlyMemory<byte>(_readBuffer, offset, count), cancellationToken);
}
else
{
- destination.Write(_readBuffer, _readOffset, count);
+ destination.Write(_readBuffer, offset, count);
+ return default;
}
- _readOffset += count;
}
private Task CopyToUntilEofAsync(Stream destination, bool async, int bufferSize, CancellationToken cancellationToken)