Skip to content

Commit

Permalink
Support multi-buffer sends in WebAssembly WebSockets
Browse files Browse the repository at this point in the history
Proposed fix for dotnet#44551
  • Loading branch information
BrennanConroy authored Nov 12, 2020
1 parent 1923bba commit d9a5e01
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -357,14 +357,21 @@ public override Task SendAsync(ArraySegment<byte> buffer, WebSocketMessageType m

WebSocketValidate.ValidateArraySegment(buffer, nameof(buffer));

_writeBuffer ??= new MemoryStream();
_writeBuffer.Write(buffer.Array!, buffer.Offset, buffer.Count);

if (!endOfMessage)
{
_writeBuffer ??= new MemoryStream();
_writeBuffer.Write(buffer.Array!, buffer.Offset, buffer.Count);
return Task.CompletedTask;
}

MemoryStream writtenBuffer = _writeBuffer;
_writeBuffer = null;

if (writtenBuffer is not null)
{
writtenBuffer.Write(buffer.Array!, buffer.Offset, buffer.Count);
}
buffer = writtenBuffer?.ToArray() ?? buffer;

try
{
Expand Down

0 comments on commit d9a5e01

Please sign in to comment.