private void OnWriteComplete(IAsyncResult result) { StreamAsyncState streamAsyncState = result.AsyncState as StreamAsyncState; if (streamAsyncState == null || streamAsyncState.Stream == null) { OnError(new NullReferenceException("State of Ssl stream is null.")); return; } AuthenticatedStream stream = streamAsyncState.Stream; try { stream.EndWrite(result); } catch (Exception e) { if (!IsIgnorableException(e)) { OnError(e); } if (EnsureSocketClosed(streamAsyncState.Client)) { OnClosed(); } return; } PosList <ArraySegment <byte> > sendingItems = streamAsyncState.SendingItems; int num = sendingItems.Position + 1; if (num < sendingItems.Count) { sendingItems.Position = num; Sendpublic(sendingItems); } else { try { m_Stream.Flush(); } catch (Exception e2) { if (!IsIgnorableException(e2)) { OnError(e2); } if (EnsureSocketClosed(streamAsyncState.Client)) { OnClosed(); } return; } OnSendingCompleted(); } }
private void OnDataRead(IAsyncResult result) { StreamAsyncState streamAsyncState = result.AsyncState as StreamAsyncState; if (streamAsyncState == null || streamAsyncState.Stream == null) { OnError(new NullReferenceException("Null state or stream.")); return; } AuthenticatedStream stream = streamAsyncState.Stream; int num = 0; try { num = stream.EndRead(result); } catch (Exception e) { if (!IsIgnorableException(e)) { OnError(e); } if (EnsureSocketClosed(streamAsyncState.Client)) { OnClosed(); } return; } if (num == 0) { if (EnsureSocketClosed(streamAsyncState.Client)) { OnClosed(); } } else { OnDataReceived(base.Buffer.Array, base.Buffer.Offset, num); BeginRead(); } }