in src/AsyncIO.cs [475:547]
bool HandleReadComplete(TransportAsyncCallbackArgs args)
{
bool completed = true;
Exception exception = null;
if (args.Exception != null)
{
exception = args.Exception;
}
else if (args.BytesTransfered == 0)
{
exception = new ObjectDisposedException(this.transport.ToString());
}
else if (args.BytesTransfered == args.Count)
{
args.ByteBuffer?.Append(args.BytesTransfered);
}
else
{
completed = false;
if (args.ByteBuffer == null)
{
args.SetBuffer(args.Buffer, args.Offset + args.BytesTransfered, args.Count - args.BytesTransfered);
}
else
{
args.ByteBuffer.Append(args.BytesTransfered);
args.SetReadBuffer(args.ByteBuffer);
}
}
if (completed)
{
if (exception != null || object.ReferenceEquals(args.CompletedCallback, onFrameComplete))
{
ByteBuffer buffer = args.ByteBuffer;
try
{
if (exception == null)
{
this.parent.OnReceiveBuffer(buffer);
}
else
{
this.parent.OnIoFault(exception);
}
}
finally
{
buffer?.Dispose();
}
}
else
{
// read size completed ok
uint size = AmqpBitConverter.ReadUInt(this.sizeBuffer, 0, this.sizeBuffer.Length);
if (size > this.maxFrameSize)
{
completed = true;
exception = new AmqpException(AmqpErrorCode.FramingError, CommonResources.GetString(CommonResources.InvalidFrameSize, size, this.maxFrameSize));
this.parent.OnIoFault(exception);
}
else
{
ByteBuffer buffer = this.parent.CreateBuffer((int)size);
args.SetReadBuffer(buffer);
args.CompletedCallback = onFrameComplete;
completed = false;
}
}
}
return completed;
}