From 29f9e43de8ef65711cad0c2a32905730e4cbf991 Mon Sep 17 00:00:00 2001 From: zivillian Date: Tue, 10 Sep 2024 21:31:50 +0200 Subject: [PATCH] remove unnecessary MemoryMarshal.TryGetArray & add missing ArrayPool.Shared.Return --- src/ism7ssl/Ism7SslStream.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/ism7ssl/Ism7SslStream.cs b/src/ism7ssl/Ism7SslStream.cs index d3bf82a..aec0eea 100644 --- a/src/ism7ssl/Ism7SslStream.cs +++ b/src/ism7ssl/Ism7SslStream.cs @@ -56,17 +56,12 @@ public override void Flush() public override int Read(byte[] buffer, int offset, int count) { - if (!MemoryMarshal.TryGetArray(buffer, out ArraySegment array)) - { - throw new NotSupportedException("could not get array from buffer"); - } - while (true) { var bytes = _protocol.GetAvailableInputBytes(); if (bytes > 0) { - return _protocol.ReadInput(array.Array, array.Offset, array.Count); + return _protocol.ReadInput(buffer, offset, count); } var readBuffer = ArrayPool.Shared.Rent(8192); @@ -178,6 +173,7 @@ public override Task FlushAsync(CancellationToken cancellationToken) bytes = await _socket.SendAsync(data, SocketFlags.None, cancellationToken); data = data.Slice(bytes); } + ArrayPool.Shared.Return(sendBuffer); } public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)