void OnHandleTransportComplete(TransportAsyncCallbackArgs args)
        {
            args.SetBuffer(null, 0, 0);
            args.CompletedCallback = null;

            if (args.Exception != null)
            {
                args.Transport.TryClose(args.Exception);
            }
            else
            {
                this.OnTransportAccepted(args);
            }
        }
Exemple #2
0
        public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
        {
            TransportAsyncCallbackArgs transportAsyncCallbackArg = new TransportAsyncCallbackArgs();

            transportAsyncCallbackArg.SetBuffer(buffer, offset, count);
            transportAsyncCallbackArg.CompletedCallback = TransportStream.onIOComplete;
            transportAsyncCallbackArg.UserToken         = this;
            transportAsyncCallbackArg.UserToken2        = Tuple.Create <AsyncCallback, object>(callback, state);
            if (!this.transport.WriteAsync(transportAsyncCallbackArg))
            {
                this.CompleteOperation(transportAsyncCallbackArg);
            }
            return(transportAsyncCallbackArg);
        }
        void OnWriteHeaderComplete(TransportAsyncCallbackArgs args)
        {
            if (args.Exception != null)
            {
                this.Complete(args);
                return;
            }

            Utils.Trace(TraceLevel.Verbose, "{0}: Write header complete. Reading header...", this);
            byte[] headerBuffer = new byte[ProtocolHeader.Size];
            args.SetBuffer(headerBuffer, 0, headerBuffer.Length);
            args.CompletedCallback = this.OnReadHeaderComplete;
            this.reader.ReadBuffer(args);
        }
Exemple #4
0
        public void WriteFrame(Performative command, bool needReply)
        {
            try
            {
                Frame frame = new Frame(FrameType.Sasl, 0, command);

                TransportAsyncCallbackArgs args = new TransportAsyncCallbackArgs();
                args.SetBuffer(frame.Buffer);
                args.CompletedCallback = this.onWriteFrameComplete;
                args.UserToken = needReply;
                this.writer.WriteBuffer(args);
            }
            catch (Exception exception)
            {
                this.HandleException(exception);
            }
        }
Exemple #5
0
            bool HandleWriteComplete(TransportAsyncCallbackArgs args)
            {
                bool done = 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.SetBuffer(args.Buffer, args.Offset + args.BytesTransfered, args.Count - args.BytesTransfered);
                    done = false;
                }

                TransportAsyncCallbackArgs innerArgs = (TransportAsyncCallbackArgs)args.UserToken;
                if (done && innerArgs.CompletedCallback != null)
                {
                    innerArgs.Exception = exception;
                    innerArgs.BytesTransfered = innerArgs.Count;
                    innerArgs.CompletedCallback(innerArgs);
                }

                return done;
            }
Exemple #6
0
 public void WriteBuffer(TransportAsyncCallbackArgs args)
 {
     TransportAsyncCallbackArgs wrapperArgs = new TransportAsyncCallbackArgs();
     wrapperArgs.SetBuffer(args.Buffer, args.Offset, args.Count);
     wrapperArgs.CompletedCallback = this.onWriteComplete;
     wrapperArgs.UserToken = args;
     this.Write(wrapperArgs);
 }
Exemple #7
0
            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.SetBuffer(args.Buffer, args.Offset + args.BytesTransfered, args.Count - args.BytesTransfered);
                    completed = false;
                }

                if (completed)
                {
                    if (exception != null || object.ReferenceEquals(args.CompletedCallback, this.onFrameComplete))
                    {
                        Action<ByteBuffer, Exception> callback = (Action<ByteBuffer, Exception>)args.UserToken;
                        ByteBuffer buffer = null;
                        if (exception == null)
                        {
                            buffer = ByteBuffer.Wrap(args.Buffer, 0, args.Buffer.Length);
                        }

                        callback(buffer, exception);
                    }
                    else
                    {
                        // read size completed ok
                        uint size = AmqpBitConverter.ReadUInt(this.sizeBuffer, 0, this.sizeBuffer.Length);
                        byte[] frameBuffer = new byte[size];
                        Buffer.BlockCopy(this.sizeBuffer, 0, frameBuffer, 0, this.sizeBuffer.Length);
                        args.SetBuffer(frameBuffer, this.sizeBuffer.Length, (int)size - this.sizeBuffer.Length);
                        args.CompletedCallback = this.onFrameComplete;
                        completed = false;
                    }
                }

                return completed;
            }
Exemple #8
0
 public void Read(Action<ByteBuffer, Exception> callback)
 {
     TransportAsyncCallbackArgs args = new TransportAsyncCallbackArgs();
     args.UserToken = callback;
     args.SetBuffer(this.sizeBuffer, 0, this.sizeBuffer.Length);
     args.CompletedCallback = this.onSizeComplete;
     this.ReadCore(args);
 }
Exemple #9
0
 public void ReadBuffer(TransportAsyncCallbackArgs args)
 {
     TransportAsyncCallbackArgs wrapperArgs = new TransportAsyncCallbackArgs();
     wrapperArgs.SetBuffer(args.Buffer, args.Offset, args.Count);
     wrapperArgs.UserToken = args;
     wrapperArgs.CompletedCallback = this.onReadComplete;
     this.Read(wrapperArgs);
 }