From 76da0f43ee79407160e561dd9b200b5db53c3299 Mon Sep 17 00:00:00 2001 From: bollhals Date: Wed, 19 Aug 2020 21:10:42 +0200 Subject: [PATCH] change from Memory to ReadOnlyMemory --- projects/RabbitMQ.Client/client/impl/Connection.cs | 2 +- projects/RabbitMQ.Client/client/impl/IFrameHandler.cs | 2 +- projects/RabbitMQ.Client/client/impl/OutgoingCommand.cs | 6 +++--- .../RabbitMQ.Client/client/impl/SocketFrameHandler.cs | 8 ++++---- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/projects/RabbitMQ.Client/client/impl/Connection.cs b/projects/RabbitMQ.Client/client/impl/Connection.cs index 7b25089618..1be83705e9 100644 --- a/projects/RabbitMQ.Client/client/impl/Connection.cs +++ b/projects/RabbitMQ.Client/client/impl/Connection.cs @@ -924,7 +924,7 @@ public override string ToString() return string.Format("Connection({0},{1})", _id, Endpoint); } - public void Write(Memory memory) + public void Write(ReadOnlyMemory memory) { _frameHandler.Write(memory); } diff --git a/projects/RabbitMQ.Client/client/impl/IFrameHandler.cs b/projects/RabbitMQ.Client/client/impl/IFrameHandler.cs index cf0dc14b62..bdb692bd1e 100644 --- a/projects/RabbitMQ.Client/client/impl/IFrameHandler.cs +++ b/projects/RabbitMQ.Client/client/impl/IFrameHandler.cs @@ -61,6 +61,6 @@ internal interface IFrameHandler void SendHeader(); - void Write(Memory memory); + void Write(ReadOnlyMemory memory); } } diff --git a/projects/RabbitMQ.Client/client/impl/OutgoingCommand.cs b/projects/RabbitMQ.Client/client/impl/OutgoingCommand.cs index 41f8c8f3e8..ed971d06fa 100644 --- a/projects/RabbitMQ.Client/client/impl/OutgoingCommand.cs +++ b/projects/RabbitMQ.Client/client/impl/OutgoingCommand.cs @@ -66,8 +66,8 @@ internal void Transmit(ushort channelNumber, Connection connection) var size = GetMaxSize(maxBodyPayloadBytes); // Will be returned by SocketFrameWriter.WriteLoop - var memory = new Memory(ArrayPool.Shared.Rent(size), 0, size); - var span = memory.Span; + var rentedArray = ArrayPool.Shared.Rent(size); + var span = rentedArray.AsSpan(0, size); var offset = Framing.Method.WriteTo(span, channelNumber, Method); if (Method.HasContent) @@ -88,7 +88,7 @@ internal void Transmit(ushort channelNumber, Connection connection) throw new InvalidOperationException($"Serialized to wrong size, expect {size}, offset {offset}"); } - connection.Write(memory); + connection.Write(new ReadOnlyMemory(rentedArray, 0, size)); } private int GetMaxSize(int maxPayloadBytes) diff --git a/projects/RabbitMQ.Client/client/impl/SocketFrameHandler.cs b/projects/RabbitMQ.Client/client/impl/SocketFrameHandler.cs index 71f1ce070c..b1c55be489 100644 --- a/projects/RabbitMQ.Client/client/impl/SocketFrameHandler.cs +++ b/projects/RabbitMQ.Client/client/impl/SocketFrameHandler.cs @@ -70,8 +70,8 @@ internal class SocketFrameHandler : IFrameHandler private readonly ITcpClient _socket; private readonly Stream _reader; private readonly Stream _writer; - private readonly ChannelWriter> _channelWriter; - private readonly ChannelReader> _channelReader; + private readonly ChannelWriter> _channelWriter; + private readonly ChannelReader> _channelReader; private readonly Task _writerTask; private readonly object _semaphore = new object(); private readonly byte[] _frameHeaderBuffer; @@ -83,7 +83,7 @@ public SocketFrameHandler(AmqpTcpEndpoint endpoint, { Endpoint = endpoint; _frameHeaderBuffer = new byte[6]; - var channel = Channel.CreateUnbounded>( + var channel = Channel.CreateUnbounded>( new UnboundedChannelOptions { AllowSynchronousContinuations = false, @@ -260,7 +260,7 @@ public void SendHeader() _writer.Flush(); } - public void Write(Memory memory) + public void Write(ReadOnlyMemory memory) { _channelWriter.TryWrite(memory); }