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)