Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change from Memory to ReadOnlyMemory #928

Merged
merged 1 commit into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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