Exemplo n.º 1
0
            public SocketReceiveAsyncResult(int size, bool throwOnEmpty, WseTcpDuplexSessionChannel channel, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.size           = size;
                this.channel        = channel;
                this.throwOnEmpty   = throwOnEmpty;
                this.bytesReadTotal = 0;
                this.buffer         = channel.bufferManager.TakeBuffer(size);

                bool success = false;

                try
                {
                    IAsyncResult socketReceiveResult = channel.BeginSocketReceive(this.buffer, bytesReadTotal, size, readBytesCallback, this);
                    if (socketReceiveResult.CompletedSynchronously)
                    {
                        if (CompleteReadBytes(socketReceiveResult))
                        {
                            base.Complete(true);
                        }
                    }
                    success = true;
                }
                finally
                {
                    if (!success)
                    {
                        this.Cleanup();
                    }
                }
            }
Exemplo n.º 2
0
            public WriteDataAsyncResult(ArraySegment <byte> data, TimeSpan timeout, WseTcpDuplexSessionChannel channel, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.channel = channel;
                this.data    = data;
                bool success = false;

                try
                {
                    preDataBytes = this.channel.GetPreDataBuffer(data);

                    IAsyncResult preDataResult = channel.BeginSocketSend(preDataBytes, preDataCallback, this);
                    if (!preDataResult.CompletedSynchronously)
                    {
                        return;
                    }

                    if (CompletePreData(preDataResult))
                    {
                        Cleanup();
                        base.Complete(true);
                    }
                    success = true;
                }
                finally
                {
                    if (!success)
                    {
                        Cleanup();
                    }
                }
            }
Exemplo n.º 3
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();
                    }
                }
            }
Exemplo n.º 4
0
            public TryReceiveAsyncResult(TimeSpan timeout, WseTcpDuplexSessionChannel channel, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.channel = channel;

                bool completeSelf = true;

                if (!channel.IsDisposed)
                {
                    try
                    {
                        IAsyncResult beginReceiveResult = this.channel.BeginReceive(timeout, receiveCallback, this);
                        if (beginReceiveResult.CompletedSynchronously)
                        {
                            CompleteReceive(beginReceiveResult);
                        }
                        else
                        {
                            completeSelf = false;
                        }
                    }
                    catch (TimeoutException)
                    {
                    }
                }

                if (completeSelf)
                {
                    base.Complete(true);
                }
            }
Exemplo n.º 5
0
            public SocketSendAsyncResult(ArraySegment <byte> buffer, WseTcpDuplexSessionChannel channel, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.channel = channel;

                IAsyncResult sendResult = channel.socket.BeginSend(buffer.Array, buffer.Offset, buffer.Count, SocketFlags.None, sendCallback, this);

                if (!sendResult.CompletedSynchronously)
                {
                    return;
                }

                CompleteSend(sendResult);
                base.Complete(true);
            }
Exemplo n.º 6
0
            public ReceiveAsyncResult(TimeSpan timeout, WseTcpDuplexSessionChannel channel, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.channel = channel;

                if (!channel.IsDisposed)
                {
                    IAsyncResult readDataResult = channel.BeginReadData(callback, state);
                    if (!readDataResult.CompletedSynchronously)
                    {
                        return;
                    }

                    CompleteReadData(readDataResult);
                }

                base.Complete(true);
            }
Exemplo n.º 7
0
            public SendAsyncResult(Message message, TimeSpan timeout, WseTcpDuplexSessionChannel channel, AsyncCallback callback, object state)
                : base(callback, state)

            {
                this.channel = channel;

                ArraySegment <byte> encodedBytes = this.channel.EncodeMessage(message);

                IAsyncResult writeResult = channel.BeginWriteData(encodedBytes, timeout, writeCallback, this);

                if (!writeResult.CompletedSynchronously)
                {
                    return;
                }

                CompleteWrite(writeResult);
                base.Complete(true);
            }
            public SendAsyncResult(Message message, TimeSpan timeout, WseTcpDuplexSessionChannel channel, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.channel = channel;

                ArraySegment<byte> encodedBytes = this.channel.EncodeMessage(message);

                IAsyncResult writeResult = channel.BeginWriteData(encodedBytes, timeout, writeCallback, this);
                if (!writeResult.CompletedSynchronously)
                {
                    return;
                }

                CompleteWrite(writeResult);
                base.Complete(true);
            }
            public ReceiveAsyncResult(TimeSpan timeout, WseTcpDuplexSessionChannel channel, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.channel = channel;

                if (!channel.IsDisposed)
                {
                    IAsyncResult readDataResult = channel.BeginReadData(callback, state);
                    if (!readDataResult.CompletedSynchronously)
                    {
                        return;
                    }

                    CompleteReadData(readDataResult);
                }

                base.Complete(true);
            }
            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();
                    }
                }
            }
            public WriteDataAsyncResult(ArraySegment<byte> data, TimeSpan timeout, WseTcpDuplexSessionChannel channel, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.channel = channel;
                this.data = data;
                bool success = false;
                try
                {
                    preDataBytes = this.channel.GetPreDataBuffer(data);

                    IAsyncResult preDataResult = channel.BeginSocketSend(preDataBytes, preDataCallback, this);
                    if (!preDataResult.CompletedSynchronously)
                    {
                        return;
                    }

                    if (CompletePreData(preDataResult))
                    {
                        Cleanup();
                        base.Complete(true);
                    }
                    success = true;
                }
                finally
                {
                    if (!success)
                    {
                        Cleanup();
                    }
                }
            }
            public TryReceiveAsyncResult(TimeSpan timeout, WseTcpDuplexSessionChannel channel, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.channel = channel;

                bool completeSelf = true;
                if (!channel.IsDisposed)
                {
                    try
                    {
                        IAsyncResult beginReceiveResult = this.channel.BeginReceive(timeout, receiveCallback, this);
                        if (beginReceiveResult.CompletedSynchronously)
                        {
                            CompleteReceive(beginReceiveResult);
                        }
                        else
                        {
                            completeSelf = false;
                        }
                    }
                    catch (TimeoutException)
                    {
                    }
                }

                if (completeSelf)
                {
                    base.Complete(true);
                }
            }
 public TcpDuplexSession(WseTcpDuplexSessionChannel channel)
 {
     this.channel = channel;
     this.id = Guid.NewGuid().ToString();
 }
            public SocketSendAsyncResult(ArraySegment<byte> buffer, WseTcpDuplexSessionChannel channel, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.channel = channel;

                IAsyncResult sendResult = channel.socket.BeginSend(buffer.Array, buffer.Offset, buffer.Count, SocketFlags.None, sendCallback,this);
                if (!sendResult.CompletedSynchronously)
                {
                    return;
                }

                CompleteSend(sendResult);
                base.Complete(true);
            }
            public SocketReceiveAsyncResult(int size, bool throwOnEmpty, WseTcpDuplexSessionChannel channel, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.size = size;
                this.channel = channel;
                this.throwOnEmpty = throwOnEmpty;
                this.bytesReadTotal = 0;
                this.buffer = channel.bufferManager.TakeBuffer(size);

                bool success = false;
                try
                {
                    IAsyncResult socketReceiveResult = channel.BeginSocketReceive(this.buffer, bytesReadTotal, size, readBytesCallback, this);
                    if (socketReceiveResult.CompletedSynchronously)
                    {
                        if (CompleteReadBytes(socketReceiveResult))
                        {
                            base.Complete(true);
                        }
                    }
                    success = true;
                }
                finally
                {
                    if (!success)
                    {
                        this.Cleanup();
                    }
                }
            }
Exemplo n.º 16
0
 public TcpDuplexSession(WseTcpDuplexSessionChannel channel)
 {
     this.channel = channel;
     this.id      = Guid.NewGuid().ToString();
 }