diff --git a/src/Websocket.Client/WebsocketClient.Sending.cs b/src/Websocket.Client/WebsocketClient.Sending.cs index 74dabc2..0e5e260 100644 --- a/src/Websocket.Client/WebsocketClient.Sending.cs +++ b/src/Websocket.Client/WebsocketClient.Sending.cs @@ -299,24 +299,7 @@ private async Task SendInternal(RequestMessage message) } _logger.LogTrace(L("Sending: {message}"), Name, message); -#if NETSTANDARD2_0 - ArraySegment payload; - switch (message) - { - case RequestTextMessage textMessage: - payload = new ArraySegment(GetEncoding().GetBytes(textMessage.Text)); - break; - case RequestBinaryMessage binaryMessage: - payload = new ArraySegment(binaryMessage.Data); - break; - case RequestBinarySegmentMessage segmentMessage: - payload = segmentMessage.Data; - break; - default: - throw new ArgumentException($"Unknown message type: {message.GetType()}"); - } -#else ReadOnlyMemory payload; switch (message) @@ -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) diff --git a/src/Websocket.Client/WebsocketClient.cs b/src/Websocket.Client/WebsocketClient.cs index 21b9878..4d036d9 100644 --- a/src/Websocket.Client/WebsocketClient.cs +++ b/src/Websocket.Client/WebsocketClient.cs @@ -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(new byte[chunkSize]); -#else var buffer = new Memory(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;