示例#1
0
        private void OnWriteComplete(IAsyncResult result)
        {
            SslStreamTcpSession.SslAsyncState asyncState = result.AsyncState as SslStreamTcpSession.SslAsyncState;
            if (asyncState == null || asyncState.SslStream == null)
            {
                this.OnError((Exception) new NullReferenceException("State of Ssl stream is null."));
            }
            else
            {
                SslStream sslStream = asyncState.SslStream;
                try {
                    sslStream.EndWrite(result);
                } catch (Exception ex) {
                    if (!this.IsIgnorableException(ex))
                    {
                        this.OnError(ex);
                    }
                    if (!this.EnsureSocketClosed(asyncState.Client))
                    {
                        return;
                    }
                    this.OnClosed();
                    return;
                }

                PosList <ArraySegment <byte> > sendingItems = asyncState.SendingItems;
                int num = sendingItems.Position + 1;
                if (num < sendingItems.Count)
                {
                    sendingItems.Position = num;
                    this.SendInternal(sendingItems);
                }
                else
                {
                    try {
                        this.m_SslStream.Flush();
                    } catch (Exception ex) {
                        if (!this.IsIgnorableException(ex))
                        {
                            this.OnError(ex);
                        }
                        if (!this.EnsureSocketClosed(asyncState.Client))
                        {
                            return;
                        }
                        this.OnClosed();
                        return;
                    }

                    this.OnSendingCompleted();
                }
            }
        }
示例#2
0
        private void DequeueSend()
        {
            PosList <ArraySegment <byte> > sendingItems = this.GetSendingItems();

            if (!this.m_SendingQueue.TryDequeue((IList <ArraySegment <byte> >)sendingItems))
            {
                this.m_IsSending = 0;
            }
            else
            {
                this.SendInternal(sendingItems);
            }
        }
示例#3
0
        protected void OnSendingCompleted()
        {
            PosList <ArraySegment <byte> > sendingItems = this.GetSendingItems();

            sendingItems.Clear();
            sendingItems.Position = 0;
            if (!this.m_SendingQueue.TryDequeue((IList <ArraySegment <byte> >)sendingItems))
            {
                this.m_IsSending = 0;
            }
            else
            {
                this.SendInternal(sendingItems);
            }
        }
示例#4
0
 protected override void SendInternal(PosList <ArraySegment <byte> > items)
 {
     global::System.Net.Sockets.Socket client = this.Client;
     try {
         ArraySegment <byte> arraySegment = items[items.Position];
         this.m_SslStream.BeginWrite(arraySegment.Array, arraySegment.Offset, arraySegment.Count,
                                     new AsyncCallback(this.OnWriteComplete), (object)new SslStreamTcpSession.SslAsyncState()
         {
             SslStream    = this.m_SslStream,
             Client       = client,
             SendingItems = items
         });
     } catch (Exception ex) {
         if (!this.IsIgnorableException(ex))
         {
             this.OnError(ex);
         }
         if (!this.EnsureSocketClosed(client))
         {
             return;
         }
         this.OnClosed();
     }
 }
示例#5
0
 protected abstract void SendInternal(PosList <ArraySegment <byte> > items);