Example #1
0
            public ReadDataAsyncResult(WseTcpDuplexSessionChannel channel, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.channel = channel;

                bool success = false;

                try
                {
                    IAsyncResult drainPreambleResult = channel.BeginSocketReceiveBytes(12, false, drainPreambleCallback, this);
                    if (drainPreambleResult.CompletedSynchronously)
                    {
                        if (CompleteDrainPreamble(drainPreambleResult))
                        {
                            base.Complete(true);
                        }
                    }
                    success = true;
                }
                finally
                {
                    if (!success)
                    {
                        this.Cleanup();
                    }
                }
            }
Example #2
0
            bool CompleteDrainPreamble(IAsyncResult result)
            {
                this.preambleBytes = channel.EndSocketReceiveBytes(result);
                if (this.preambleBytes == null)
                {
                    this.buffer = new ArraySegment <byte>();
                    return(true);
                }

                int idLength, typeLength;

                channel.PrepareDummyRead(preambleBytes, out idLength, out typeLength);

                IAsyncResult dummyResult = channel.BeginSocketReceiveBytes(idLength + typeLength, dummyCallback, this);

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

                return(CompleteDummy(dummyResult));
            }
            public ReadDataAsyncResult(WseTcpDuplexSessionChannel channel, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.channel = channel;

                bool success = false;
                try
                {
                    IAsyncResult drainPreambleResult = channel.BeginSocketReceiveBytes(12, false, drainPreambleCallback, this);
                    if (drainPreambleResult.CompletedSynchronously)
                    {
                        if (CompleteDrainPreamble(drainPreambleResult))
                        {
                            base.Complete(true);
                        }
                    }
                    success = true;
                }
                finally
                {
                    if (!success)
                    {
                        this.Cleanup();
                    }
                }
            }