Inheritance: WebSocket, IDisposable
コード例 #1
0
ファイル: WebSocketBase.cs プロジェクト: dotnet/corefx
 public override void StartTimer(WebSocketBase webSocket)
 {
 }
コード例 #2
0
ファイル: WebSocketBase.cs プロジェクト: dotnet/corefx
                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);
                }
コード例 #3
0
ファイル: WebSocketBase.cs プロジェクト: dotnet/corefx
 public CloseOutputOperation(WebSocketBase webSocket)
     : base(webSocket)
 {
     BufferType = WebSocketProtocolComponent.BufferType.Close;
 }
コード例 #4
0
ファイル: WebSocketBase.cs プロジェクト: dotnet/corefx
 public abstract void StartTimer(WebSocketBase webSocket);
コード例 #5
0
        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);
            }
        }
コード例 #6
0
 internal WebSocketOperation(WebSocketBase webSocket)
 {
     Contract.Assert(webSocket != null, "'webSocket' MUST NOT be NULL.");
     m_WebSocket = webSocket;
 }
コード例 #7
0
 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);
 }
コード例 #8
0
        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);
            }
        }
コード例 #9
0
        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)
            {
            }
        }
コード例 #10
0
 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));
     }
 }
コード例 #11
0
        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));
        }
コード例 #12
0
        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);
        }
コード例 #13
0
            public HttpListenerAsyncEventArgs(WebSocketBase webSocket, WebSocketHttpListenerDuplexStream stream)
                : base()
            {
                m_WebSocket = webSocket;
                m_CurrentStream = stream;
                m_AllocateOverlappedOnDemand = LocalAppContextSwitches.AllocateOverlappedOnDemand;

                if (!m_AllocateOverlappedOnDemand)
                {
                    InitializeOverlapped();
                }
            }
コード例 #14
0
        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;
            }
        }
コード例 #15
0
ファイル: WebSocketBase.cs プロジェクト: dotnet/corefx
 internal WebSocketOperation(WebSocketBase webSocket)
 {
     Debug.Assert(webSocket != null, "'webSocket' MUST NOT be NULL.");
     _webSocket = webSocket;
     AsyncOperationCompleted = false;
 }
コード例 #16
0
 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;
 }
コード例 #17
0
ファイル: WebSocketBase.cs プロジェクト: dotnet/corefx
 public ReceiveOperation(WebSocketBase webSocket)
     : base(webSocket)
 {
 }
コード例 #18
0
 public HttpListenerAsyncEventArgs(WebSocketBase webSocket, WebSocketHttpListenerDuplexStream stream)
     : base()
 {
     m_WebSocket = webSocket;
     m_CurrentStream = stream;
     InitializeOverlapped();
 }
コード例 #19
0
ファイル: WebSocketBase.cs プロジェクト: dotnet/corefx
 public SendOperation(WebSocketBase webSocket)
     : base(webSocket)
 {
 }
コード例 #20
0
 public HttpListenerAsyncEventArgs(WebSocketBase webSocket, WebSocketHttpListenerDuplexStream stream)
     : base()
 {
     _webSocket = webSocket;
     _currentStream = stream;
 }
コード例 #21
0
        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);
        }