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(); } } }
private void OnDataRead(IAsyncResult result) { SslStreamTcpSession.SslAsyncState asyncState = result.AsyncState as SslStreamTcpSession.SslAsyncState; if (asyncState == null || asyncState.SslStream == null) { this.OnError((Exception) new NullReferenceException("Null state or stream.")); } else { SslStream sslStream = asyncState.SslStream; int length; try { length = sslStream.EndRead(result); } catch (Exception ex) { if (!this.IsIgnorableException(ex)) { this.OnError(ex); } if (!this.EnsureSocketClosed(asyncState.Client)) { return; } this.OnClosed(); return; } if (length == 0) { if (!this.EnsureSocketClosed(asyncState.Client)) { return; } this.OnClosed(); } else { this.OnDataReceived(this.Buffer.Array, this.Buffer.Offset, length); this.BeginRead(); } } }