Exemplo n.º 1
0
            public ReadDataAsyncResult(SizedTcpBaseChannel channel, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.channel = channel;

                bool success = false;

                try
                {
                    IAsyncResult drainLengthResult = channel.BeginSocketReceiveBytes(4, false, OnDrainLength, this);
                    if (drainLengthResult.CompletedSynchronously)
                    {
                        if (CompleteDrainLength(drainLengthResult))
                        {
                            base.Complete(true);
                        }
                    }

                    success = true;
                }
                catch (CommunicationException e)
                {
                    base.Complete(true, e);
                }
                finally
                {
                    if (!success)
                    {
                        this.Cleanup();
                    }
                }
            }
Exemplo n.º 2
0
            bool CompleteDrainLength(IAsyncResult result)
            {
                this.lengthBytes = channel.EndSocketReceiveBytes(result);
                if (this.lengthBytes == null)
                {
                    this.buffer = new ArraySegment <byte>();
                    return(true);
                }

                this.dataLength = Formatting.BytesToSize(this.lengthBytes, 0);

                IAsyncResult readDataResult = channel.BeginSocketReceiveBytes(this.dataLength, OnReadData, this);

                if (!readDataResult.CompletedSynchronously)
                {
                    return(false);
                }

                return(CompleteReadData(result));
            }
Exemplo n.º 3
0
            public ReadDataAsyncResult(SizedTcpBaseChannel channel, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.channel = channel;

                bool success = false;
                try
                {
                    IAsyncResult drainLengthResult = channel.BeginSocketReceiveBytes(4, false, OnDrainLength, this);
                    if (drainLengthResult.CompletedSynchronously)
                    {
                        if (CompleteDrainLength(drainLengthResult))
                        {
                            base.Complete(true);
                        }
                    }

                    success = true;
                }
                catch (CommunicationException e)
                {
                    base.Complete(true, e);
                }
                finally
                {
                    if (!success)
                    {
                        this.Cleanup();
                    }
                }
            }