public override void StartTimer(WebSocketBase webSocket) { }
public override void StartTimer(WebSocketBase webSocket) { Debug.Assert(webSocket != null, "'webSocket' MUST NOT be NULL."); Debug.Assert(webSocket._keepAliveTracker != null, "'webSocket._KeepAliveTracker' MUST NOT be NULL at this point."); int keepAliveIntervalMilliseconds = (int)_keepAliveInterval.TotalMilliseconds; Debug.Assert(keepAliveIntervalMilliseconds > 0, "'keepAliveIntervalMilliseconds' MUST be POSITIVE."); // The correct pattern is to first initialize the Timer object, assign it to the member variable // and only afterwards enable the Timer. This is required because the constructor, together with // the assignment are not guaranteed to be an atomic operation, which creates a race between the // assignment and the Timer callback. _keepAliveTimer = new Timer(s_KeepAliveTimerElapsedCallback, webSocket, Timeout.Infinite, Timeout.Infinite); _keepAliveTimer.Change(keepAliveIntervalMilliseconds, Timeout.Infinite); }
public CloseOutputOperation(WebSocketBase webSocket) : base(webSocket) { BufferType = WebSocketProtocolComponent.BufferType.Close; }
public abstract void StartTimer(WebSocketBase webSocket);
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); } }
internal WebSocketOperation(WebSocketBase webSocket) { Contract.Assert(webSocket != null, "'webSocket' MUST NOT be NULL."); m_WebSocket = webSocket; }
private static WebSocketException ConvertObjectDisposedException(WebSocketBase webSocket, ObjectDisposedException innerException) { return new WebSocketException(WebSocketError.InvalidState, SR.Format(SR.net_WebSockets_InvalidState_ClosedOrAborted, webSocket.GetType().FullName, webSocket.State), innerException); }
public void SwitchToOpaqueMode(WebSocketBase webSocket) { Contract.Assert(webSocket != null, "'webSocket' MUST NOT be NULL."); Contract.Assert(m_OutputStream != null, "'m_OutputStream' MUST NOT be NULL."); Contract.Assert(m_OutputStream.InternalHttpContext != null, "'m_OutputStream.InternalHttpContext' MUST NOT be NULL."); Contract.Assert(m_OutputStream.InternalHttpContext.Response != null, "'m_OutputStream.InternalHttpContext.Response' MUST NOT be NULL."); Contract.Assert(m_OutputStream.InternalHttpContext.Response.SentHeaders, "Headers MUST have been sent at this point."); Contract.Assert(!m_InOpaqueMode, "SwitchToOpaqueMode MUST NOT be called multiple times."); if (m_InOpaqueMode) { throw new InvalidOperationException(); } m_WebSocket = webSocket; m_InOpaqueMode = true; m_ReadEventArgs = new HttpListenerAsyncEventArgs(webSocket, this); m_ReadEventArgs.Completed += s_OnReadCompleted; m_WriteEventArgs = new HttpListenerAsyncEventArgs(webSocket, this); m_WriteEventArgs.Completed += s_OnWriteCompleted; if (WebSocketBase.LoggingEnabled) { Logging.Associate(Logging.WebSockets, this, webSocket); } }
internal static void WebSocketCompleteAction(WebSocketBase webSocket, IntPtr actionContext, int bytesTransferred) { Debug.Assert(webSocket != null, "'webSocket' MUST NOT be NULL or INVALID."); Debug.Assert(webSocket.SessionHandle != null && !webSocket.SessionHandle.IsInvalid, "'webSocket.SessionHandle' MUST NOT be NULL or INVALID."); Debug.Assert(actionContext != IntPtr.Zero, "'actionContext' MUST NOT be IntPtr.Zero."); Debug.Assert(bytesTransferred >= 0, "'bytesTransferred' MUST NOT be negative."); if (webSocket.SessionHandle.IsClosed) { return; } try { Interop.WebSocket.WebSocketCompleteAction(webSocket.SessionHandle, actionContext, (uint)bytesTransferred); } catch (ObjectDisposedException) { } }
private static void ThrowIfSessionHandleClosed(WebSocketBase webSocket) { if (webSocket.SessionHandle.IsClosed) { throw new WebSocketException(WebSocketError.InvalidState, SR.Format(SR.net_WebSockets_InvalidState_ClosedOrAborted, webSocket.GetType().FullName, webSocket.State)); } }
internal static void WebSocketGetAction(WebSocketBase webSocket, ActionQueue actionQueue, Interop.WebSocket.Buffer[] dataBuffers, ref uint dataBufferCount, out Action action, out BufferType bufferType, out IntPtr actionContext) { Debug.Assert(webSocket != null, "'webSocket' MUST NOT be NULL or INVALID."); Debug.Assert(webSocket.SessionHandle != null && !webSocket.SessionHandle.IsInvalid, "'webSocket.SessionHandle' MUST NOT be NULL or INVALID."); Debug.Assert(dataBufferCount >= 0, "'dataBufferCount' MUST NOT be negative."); Debug.Assert((dataBuffers == null && dataBufferCount == 0) || (dataBuffers != null && dataBufferCount == dataBuffers.Length), "'dataBufferCount' MUST MATCH 'dataBuffers.Length'."); action = Action.NoAction; bufferType = BufferType.None; actionContext = IntPtr.Zero; IntPtr dummy; ThrowIfSessionHandleClosed(webSocket); int errorCode; try { errorCode = Interop.WebSocket.WebSocketGetAction(webSocket.SessionHandle, actionQueue, dataBuffers, ref dataBufferCount, out action, out bufferType, out dummy, out actionContext); } catch (ObjectDisposedException innerException) { throw ConvertObjectDisposedException(webSocket, innerException); } ThrowOnError(errorCode); webSocket.ValidateNativeBuffers(action, bufferType, dataBuffers, dataBufferCount); Debug.Assert(dataBufferCount >= 0); Debug.Assert((dataBufferCount == 0 && dataBuffers == null) || (dataBufferCount <= dataBuffers.Length)); }
internal static void WebSocketReceive(WebSocketBase webSocket) { Debug.Assert(webSocket != null, "'webSocket' MUST NOT be NULL or INVALID."); Debug.Assert(webSocket.SessionHandle != null && !webSocket.SessionHandle.IsInvalid, "'webSocket.SessionHandle' MUST NOT be NULL or INVALID."); ThrowIfSessionHandleClosed(webSocket); int errorCode; try { errorCode = Interop.WebSocket.WebSocketReceive(webSocket.SessionHandle, IntPtr.Zero, IntPtr.Zero); } catch (ObjectDisposedException innerException) { throw ConvertObjectDisposedException(webSocket, innerException); } ThrowOnError(errorCode); }
public HttpListenerAsyncEventArgs(WebSocketBase webSocket, WebSocketHttpListenerDuplexStream stream) : base() { m_WebSocket = webSocket; m_CurrentStream = stream; m_AllocateOverlappedOnDemand = LocalAppContextSwitches.AllocateOverlappedOnDemand; if (!m_AllocateOverlappedOnDemand) { InitializeOverlapped(); } }
public void SwitchToOpaqueMode(WebSocketBase webSocket) { Contract.Assert(webSocket != null, "'webSocket' MUST NOT be NULL."); Contract.Assert(!m_InOpaqueMode, "SwitchToOpaqueMode MUST NOT be called multiple times."); if (m_InOpaqueMode) { throw new InvalidOperationException(); } m_WebSocketConnection = BaseStream as WebSocketConnection; if (m_WebSocketConnection != null && m_IsFastPathAllowed) { if (WebSocketBase.LoggingEnabled) { Logging.Associate(Logging.WebSockets, this, m_WebSocketConnection); } m_WebSocketConnection.SwitchToOpaqueMode(webSocket); m_InOpaqueMode = true; } }
internal WebSocketOperation(WebSocketBase webSocket) { Debug.Assert(webSocket != null, "'webSocket' MUST NOT be NULL."); _webSocket = webSocket; AsyncOperationCompleted = false; }
public void SwitchToOpaqueMode(WebSocketBase webSocket) { Contract.Assert(webSocket != null, "'webSocket' MUST NOT be NULL."); Contract.Assert(!m_InOpaqueMode, "SwitchToOpaqueMode MUST NOT be called multiple times."); m_WebSocket = webSocket; m_InOpaqueMode = true; m_ReadEventArgs = new SocketAsyncEventArgs(); m_ReadEventArgs.UserToken = this; m_ReadEventArgs.Completed += s_OnReadCompleted; m_WriteEventArgs = new SocketAsyncEventArgs(); m_WriteEventArgs.UserToken = this; m_WriteEventArgs.Completed += s_OnWriteCompleted; }
public ReceiveOperation(WebSocketBase webSocket) : base(webSocket) { }
public HttpListenerAsyncEventArgs(WebSocketBase webSocket, WebSocketHttpListenerDuplexStream stream) : base() { m_WebSocket = webSocket; m_CurrentStream = stream; InitializeOverlapped(); }
public SendOperation(WebSocketBase webSocket) : base(webSocket) { }
public HttpListenerAsyncEventArgs(WebSocketBase webSocket, WebSocketHttpListenerDuplexStream stream) : base() { _webSocket = webSocket; _currentStream = stream; }
internal static void WebSocketSendWithoutBody(WebSocketBase webSocket, BufferType bufferType) { Contract.Assert(webSocket != null, "'webSocket' MUST NOT be NULL or INVALID."); Contract.Assert(webSocket.SessionHandle != null && !webSocket.SessionHandle.IsInvalid, "'webSocket.SessionHandle' MUST NOT be NULL or INVALID."); ThrowIfSessionHandleClosed(webSocket); int errorCode; try { errorCode = WebSocketSendWithoutBody_Raw(webSocket.SessionHandle, bufferType, IntPtr.Zero, IntPtr.Zero); } catch (ObjectDisposedException innerException) { throw ConvertObjectDisposedException(webSocket, innerException); } ThrowOnError(errorCode); }