public void SwitchToOpaqueMode(WebSocketBase webSocket)
{
Debug.Assert(webSocket != null, "'webSocket' MUST NOT be NULL.");
Debug.Assert(_outputStream != null, "'m_OutputStream' MUST NOT be NULL.");
Debug.Assert(_outputStream.InternalHttpContext != null,
"'m_OutputStream.InternalHttpContext' MUST NOT be NULL.");
Debug.Assert(_outputStream.InternalHttpContext.Response != null,
"'m_OutputStream.InternalHttpContext.Response' MUST NOT be NULL.");
Debug.Assert(_outputStream.InternalHttpContext.Response.SentHeaders,
"Headers MUST have been sent at this point.");
Debug.Assert(!_inOpaqueMode, "SwitchToOpaqueMode MUST NOT be called multiple times.");
if (_inOpaqueMode)
{
throw new InvalidOperationException();
}
_webSocket = webSocket;
_inOpaqueMode = true;
_readEventArgs = new HttpListenerAsyncEventArgs(webSocket, this);
_readEventArgs.Completed += s_OnReadCompleted;
_writeEventArgs = new HttpListenerAsyncEventArgs(webSocket, this);
_writeEventArgs.Completed += s_OnWriteCompleted;
if (NetEventSource.IsEnabled)
{
NetEventSource.Associate(this, webSocket);
}
}