コード例 #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();
                    }
                }
            }
コード例 #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();
                    }
                }
            }
コード例 #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();
                    }
                }
            }
コード例 #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);
                }
            }
コード例 #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);
            }
コード例 #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);
            }
コード例 #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);
            }
コード例 #8
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);
            }
コード例 #9
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);
            }
コード例 #10
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();
                    }
                }
            }
コード例 #11
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();
                    }
                }
            }
コード例 #12
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);
                }
            }
コード例 #13
0
 public TcpDuplexSession(WseTcpDuplexSessionChannel channel)
 {
     this.channel = channel;
     this.id = Guid.NewGuid().ToString();
 }
コード例 #14
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);
            }
コード例 #15
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();
                    }
                }
            }
コード例 #16
0
 public TcpDuplexSession(WseTcpDuplexSessionChannel channel)
 {
     this.channel = channel;
     this.id      = Guid.NewGuid().ToString();
 }