Skip to content

Commit

Permalink
remove unnecessary MemoryMarshal.TryGetArray & add missing ArrayPool.…
Browse files Browse the repository at this point in the history
…Shared.Return
  • Loading branch information
zivillian committed Sep 10, 2024
1 parent e262be3 commit 29f9e43
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/ism7ssl/Ism7SslStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,12 @@ public override void Flush()

public override int Read(byte[] buffer, int offset, int count)
{
if (!MemoryMarshal.TryGetArray(buffer, out ArraySegment<byte> 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<byte>.Shared.Rent(8192);
Expand Down Expand Up @@ -178,6 +173,7 @@ public override Task FlushAsync(CancellationToken cancellationToken)
bytes = await _socket.SendAsync(data, SocketFlags.None, cancellationToken);
data = data.Slice(bytes);
}
ArrayPool<byte>.Shared.Return(sendBuffer);
}

public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
Expand Down

0 comments on commit 29f9e43

Please sign in to comment.