Skip to content

Commit

Permalink
Remove NETSTANDARD2_0 pragma conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
Odonno committed Sep 24, 2023
1 parent 84ebd4a commit e062618
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 32 deletions.
18 changes: 0 additions & 18 deletions src/Websocket.Client/WebsocketClient.Sending.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,24 +299,7 @@ private async Task SendInternal(RequestMessage message)
}

_logger.LogTrace(L("Sending: {message}"), Name, message);
#if NETSTANDARD2_0
ArraySegment<byte> payload;

switch (message)
{
case RequestTextMessage textMessage:
payload = new ArraySegment<byte>(GetEncoding().GetBytes(textMessage.Text));
break;
case RequestBinaryMessage binaryMessage:
payload = new ArraySegment<byte>(binaryMessage.Data);
break;
case RequestBinarySegmentMessage segmentMessage:
payload = segmentMessage.Data;
break;
default:
throw new ArgumentException($"Unknown message type: {message.GetType()}");
}
#else
ReadOnlyMemory<byte> payload;

switch (message)
Expand All @@ -333,7 +316,6 @@ private async Task SendInternal(RequestMessage message)
default:
throw new ArgumentException($"Unknown message type: {message.GetType()}");
}
#endif

await _client!
.SendAsync(payload, WebSocketMessageType.Text, true, _cancellation?.Token ?? CancellationToken.None)
Expand Down
15 changes: 1 addition & 14 deletions src/Websocket.Client/WebsocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -453,30 +453,17 @@ private async Task Listen(WebSocket client, CancellationToken token)
{
// define buffer here and reuse, to avoid more allocation
const int chunkSize = 1024 * 4;
#if NETSTANDARD2_0
var buffer = new ArraySegment<byte>(new byte[chunkSize]);
#else
var buffer = new Memory<byte>(new byte[chunkSize]);
#endif

do
{
#if NETSTANDARD2_0
WebSocketReceiveResult result;
#else
ValueWebSocketReceiveResult result;
#endif
var ms = _memoryStreamManager.GetStream() as RecyclableMemoryStream;

while (true)
{
result = await client.ReceiveAsync(buffer, token);

#if NETSTANDARD2_0
ms.Write(buffer.AsSpan(0, result.Count));
#else
ms.Write(buffer[..result.Count].Span);
#endif
ms!.Write(buffer[..result.Count].Span);

if (result.EndOfMessage)
break;
Expand Down

0 comments on commit e062618

Please sign in to comment.