System.Net.WebSockets.WebSocketProtocolComponent.WebSocketCreateServerHandle C# (CSharp) Method

WebSocketCreateServerHandle() static private method

static private WebSocketCreateServerHandle ( Interop properties, int propertyCount, SafeWebSocketHandle &webSocketHandle ) : void
properties Interop
propertyCount int
webSocketHandle SafeWebSocketHandle
return void
        internal static void WebSocketCreateServerHandle(Interop.WebSocket.Property[] properties,
            int propertyCount,
            out SafeWebSocketHandle webSocketHandle)
        {
            Debug.Assert(propertyCount >= 0, "'propertyCount' MUST NOT be negative.");
            Debug.Assert((properties == null && propertyCount == 0) ||
                (properties != null && propertyCount == properties.Length),
                "'propertyCount' MUST MATCH 'properties.Length'.");

            if (s_webSocketDllHandle.IsInvalid)
            {
                WebSocketValidate.ThrowPlatformNotSupportedException_WSPC();
            }

            int errorCode = Interop.WebSocket.WebSocketCreateServerHandle(properties, (uint)propertyCount, out webSocketHandle);
            ThrowOnError(errorCode);

            if (webSocketHandle == null ||
                webSocketHandle.IsInvalid)
            {
                WebSocketValidate.ThrowPlatformNotSupportedException_WSPC();
            }

            IntPtr responseHeadersPtr;
            uint responseHeaderCount;

            // Currently the WSPC doesn't allow to initiate a data session
            // without also being involved in the http handshake
            // There is no information whatsoever, which is needed by the
            // WSPC for parsing WebSocket frames from the HTTP handshake
            // In the managed implementation the HTTP header handling
            // will be done using the managed HTTP stack and we will
            // just fake an HTTP handshake for the WSPC calling
            // WebSocketBeginServerHandshake and WebSocketEndServerHandshake
            // with statically defined dummy headers.
            errorCode = Interop.WebSocket.WebSocketBeginServerHandshake(webSocketHandle,
                IntPtr.Zero,
                IntPtr.Zero,
                0,
                s_ServerFakeRequestHeaders,
                (uint)s_ServerFakeRequestHeaders.Length,
                out responseHeadersPtr,
                out responseHeaderCount);

            ThrowOnError(errorCode);

            Interop.WebSocket.HttpHeader[] responseHeaders = MarshalHttpHeaders(responseHeadersPtr, (int)responseHeaderCount);
            errorCode = Interop.WebSocket.WebSocketEndServerHandshake(webSocketHandle);

            ThrowOnError(errorCode);

            Debug.Assert(webSocketHandle != null, "'webSocketHandle' MUST NOT be NULL at this point.");
        }

Usage Example

示例#1
0
 private SafeHandle CreateWebSocketHandle()
 {
     Debug.Assert(_properties != null, "'_properties' MUST NOT be NULL.");
     return(WebSocketProtocolComponent.WebSocketCreateServerHandle(
                _properties,
                _properties.Length));
 }
All Usage Examples Of System.Net.WebSockets.WebSocketProtocolComponent::WebSocketCreateServerHandle