Skip to content

Commit

Permalink
[release/5.0] Support multi-buffer sends in WebAssembly WebSockets (d…
Browse files Browse the repository at this point in the history
…otnet#44665)

* Support multi-buffer sends in WebAssembly WebSockets

Proposed fix for dotnet#44551

* Update BrowserWebSocket.cs

* Whitespace

* TryGetBuffer

Co-authored-by: Brennan <[email protected]>
  • Loading branch information
github-actions[bot] and BrennanConroy authored Nov 18, 2020
1 parent f4f9088 commit a05d753
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,29 @@ 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;
MemoryStream? writtenBuffer = _writeBuffer;
_writeBuffer = null;

if (writtenBuffer is not null)
{
writtenBuffer.Write(buffer.Array!, buffer.Offset, buffer.Count);
if (writtenBuffer.TryGetBuffer(out var tmpBuffer))
{
buffer = tmpBuffer;
}
else
{
buffer = writtenBuffer.ToArray();
}
}

try
{
switch (messageType)
Expand Down

0 comments on commit a05d753

Please sign in to comment.