Microsoft.Azure.Amqp.AsyncIO.AsyncReader.HandleReadBufferComplete C# (CSharp) Method

HandleReadBufferComplete() private method

private HandleReadBufferComplete ( TransportAsyncCallbackArgs args ) : bool
args Microsoft.Azure.Amqp.Transport.TransportAsyncCallbackArgs
return bool
            bool HandleReadBufferComplete(TransportAsyncCallbackArgs args)
            {
                bool shouldContinue;
                if (args.Exception != null)
                {
                    this.asyncIo.ioHandler.OnIoFault(args.Exception);
                    shouldContinue = false;
                }
                else if (args.BytesTransfered == 0)
                {
                    // connection closed by other side
                    this.asyncIo.ioHandler.OnIoFault(new AmqpException(AmqpErrorCode.ConnectionForced, null));
                    shouldContinue = false;
                }
                else
                {
                    Fx.Assert(this.remainingBytes == args.Count, "remaining bytes should be the same as args.Count");
                    Fx.Assert(this.remainingBytes >= args.BytesTransfered, "remaining bytes cannot be less than args.BytesTransfered " + this.remainingBytes);
                    shouldContinue = true;
                    this.remainingBytes -= args.BytesTransfered;

                    if (this.remainingBytes > 0)
                    {
                        // Buffer partially completed.
                        Fx.Assert(args.BytesTransfered < args.Count, "bytes transfered should be less than count");
                        args.SetBuffer(args.Buffer, args.Offset + args.BytesTransfered, args.Count - args.BytesTransfered);
                    }
                    else
                    {
                        Fx.Assert(this.remainingBytes == 0, "remaining bytes should be 0");
                        switch (this.readState)
                        {
                            case ReadState.FrameBody:
                                this.HandleFrameBodyReadComplete(args);
                                break;
                            case ReadState.FrameSize:
                                this.HandleFrameSizeReadComplete(args);
                                break;
                            case ReadState.ProtocolHeader:
                                this.HandleProtocolHeaderReadComplete(args);
                                break;
                            default:
                                throw new AmqpException(AmqpErrorCode.IllegalState, null);
                        }
                    }
                }

                if (!shouldContinue)
                {
                    this.Cleanup();
                }

                return shouldContinue;
            }