Skip to content

Commit

Permalink
Merge pull request #928 from bollhals/ROM
Browse files Browse the repository at this point in the history
change from Memory to ReadOnlyMemory
  • Loading branch information
michaelklishin authored Aug 19, 2020
2 parents 1285469 + 76da0f4 commit bef2029
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion projects/RabbitMQ.Client/client/impl/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ public override string ToString()
return string.Format("Connection({0},{1})", _id, Endpoint);
}

public void Write(Memory<byte> memory)
public void Write(ReadOnlyMemory<byte> memory)
{
_frameHandler.Write(memory);
}
Expand Down
2 changes: 1 addition & 1 deletion projects/RabbitMQ.Client/client/impl/IFrameHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ internal interface IFrameHandler

void SendHeader();

void Write(Memory<byte> memory);
void Write(ReadOnlyMemory<byte> memory);
}
}
6 changes: 3 additions & 3 deletions projects/RabbitMQ.Client/client/impl/OutgoingCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<byte>(ArrayPool<byte>.Shared.Rent(size), 0, size);
var span = memory.Span;
var rentedArray = ArrayPool<byte>.Shared.Rent(size);
var span = rentedArray.AsSpan(0, size);

var offset = Framing.Method.WriteTo(span, channelNumber, Method);
if (Method.HasContent)
Expand All @@ -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<byte>(rentedArray, 0, size));
}

private int GetMaxSize(int maxPayloadBytes)
Expand Down
8 changes: 4 additions & 4 deletions projects/RabbitMQ.Client/client/impl/SocketFrameHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ internal class SocketFrameHandler : IFrameHandler
private readonly ITcpClient _socket;
private readonly Stream _reader;
private readonly Stream _writer;
private readonly ChannelWriter<Memory<byte>> _channelWriter;
private readonly ChannelReader<Memory<byte>> _channelReader;
private readonly ChannelWriter<ReadOnlyMemory<byte>> _channelWriter;
private readonly ChannelReader<ReadOnlyMemory<byte>> _channelReader;
private readonly Task _writerTask;
private readonly object _semaphore = new object();
private readonly byte[] _frameHeaderBuffer;
Expand All @@ -83,7 +83,7 @@ public SocketFrameHandler(AmqpTcpEndpoint endpoint,
{
Endpoint = endpoint;
_frameHeaderBuffer = new byte[6];
var channel = Channel.CreateUnbounded<Memory<byte>>(
var channel = Channel.CreateUnbounded<ReadOnlyMemory<byte>>(
new UnboundedChannelOptions
{
AllowSynchronousContinuations = false,
Expand Down Expand Up @@ -260,7 +260,7 @@ public void SendHeader()
_writer.Flush();
}

public void Write(Memory<byte> memory)
public void Write(ReadOnlyMemory<byte> memory)
{
_channelWriter.TryWrite(memory);
}
Expand Down

0 comments on commit bef2029

Please sign in to comment.