public void FinishWrite(IList <ArraySegment <byte> > buffer, ref int offset) { if (!_isConnected) { _delegate.FinishWrite(buffer, ref offset); return; } else if (SslStream == null) // Transceiver was closed { int remaining = buffer.GetByteCount() - offset; if (GetSendPacketSize(remaining) == remaining) // Sent last packet { offset = remaining; // Assume all the data was sent for at-most-once semantics. } _writeResult = null; return; } else if (!_authenticated) { FinishAuthenticate(); return; } Debug.Assert(_writeResult != null); int bytesTransferred = GetSendPacketSize(buffer.GetByteCount() - offset); try { SslStream.EndWrite(_writeResult); offset += bytesTransferred; } catch (IOException ex) { if (Network.ConnectionLost(ex)) { throw new ConnectionLostException(ex); } if (Network.Timeout(ex)) { throw new ConnectionTimeoutException(); } throw new TransportException(ex); } catch (ObjectDisposedException ex) { throw new ConnectionLostException(ex); } }