Inheritance: Microsoft.Win32.SafeHandles.CriticalHandleZeroOrMinusOneIsInvalid
 private unsafe void SetupV2Config()
 {
     uint num = 0;
     ulong serverSessionId = 0L;
     if (!this.m_V2Initialized)
     {
         try
         {
             num = UnsafeNclNativeMethods.HttpApi.HttpCreateServerSession(UnsafeNclNativeMethods.HttpApi.Version, &serverSessionId, 0);
             if (num != 0)
             {
                 throw new HttpListenerException((int) num);
             }
             this.m_ServerSessionHandle = new HttpServerSessionHandle(serverSessionId);
             serverSessionId = 0L;
             num = UnsafeNclNativeMethods.HttpApi.HttpCreateUrlGroup(this.m_ServerSessionHandle.DangerousGetServerSessionId(), &serverSessionId, 0);
             if (num != 0)
             {
                 throw new HttpListenerException((int) num);
             }
             this.m_UrlGroupId = serverSessionId;
             this.m_V2Initialized = true;
         }
         catch (Exception exception)
         {
             this.m_State = 2;
             if (this.m_ServerSessionHandle != null)
             {
                 this.m_ServerSessionHandle.Close();
             }
             if (Logging.On)
             {
                 Logging.Exception(Logging.HttpListener, this, "SetupV2Config", exception);
             }
             throw;
         }
     }
 }
Exemplo n.º 2
0
        private void SetupV2Config()
        {
            uint statusCode = Interop.HttpApi.ERROR_SUCCESS;
            ulong id = 0;

            //
            // If we have already initialized V2 config, then nothing to do.
            //
            if (_V2Initialized)
            {
                return;
            }

            //
            // V2 initialization sequence:
            // 1. Create server session
            // 2. Create url group
            // 3. Create request queue - Done in Start()
            // 4. Add urls to url group - Done in Start()
            // 5. Attach request queue to url group - Done in Start()
            //

            try
            {
                statusCode = Interop.HttpApi.HttpCreateServerSession(
                    Interop.HttpApi.s_version, &id, 0);

                if (statusCode != Interop.HttpApi.ERROR_SUCCESS)
                {
                    throw new HttpListenerException((int)statusCode);
                }

                Debug.Assert(id != 0, "Invalid id returned by HttpCreateServerSession");

                _serverSessionHandle = new HttpServerSessionHandle(id);

                id = 0;
                statusCode = Interop.HttpApi.HttpCreateUrlGroup(
                    _serverSessionHandle.DangerousGetServerSessionId(), &id, 0);

                if (statusCode != Interop.HttpApi.ERROR_SUCCESS)
                {
                    throw new HttpListenerException((int)statusCode);
                }

                Debug.Assert(id != 0, "Invalid id returned by HttpCreateUrlGroup");
                _urlGroupId = id;

                _V2Initialized = true;
            }
            catch (Exception exception)
            {
                //
                // If V2 initialization fails, we mark object as unusable.
                //
                _state = State.Closed;

                //
                // If Url group or request queue creation failed, close server session before throwing.
                //
                _serverSessionHandle?.Dispose();

                if (NetEventSource.IsEnabled) NetEventSource.Error(this, $"SetupV2Config {exception}");
                throw;
            }
        }
Exemplo n.º 3
0
        private void SetupV2Config() {
            uint statusCode = UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS;
            ulong id = 0;

            //
            // If we have already initialized V2 config, then nothing to do.
            //
            if (m_V2Initialized) {
                return;
            }

            //
            // V2 initialization sequence:
            // 1. Create server session
            // 2. Create url group
            // 3. Create request queue - Done in Start()
            // 4. Add urls to url group - Done in Start()
            // 5. Attach request queue to url group - Done in Start()
            //

            try {
                statusCode = UnsafeNclNativeMethods.HttpApi.HttpCreateServerSession(
                    UnsafeNclNativeMethods.HttpApi.Version, &id, 0);

                if (statusCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS) {
                    throw new HttpListenerException((int)statusCode);
                }

                GlobalLog.Assert(id != 0, "Invalid id returned by HttpCreateServerSession");
                
                m_ServerSessionHandle = new HttpServerSessionHandle(id);

                id = 0;
                statusCode = UnsafeNclNativeMethods.HttpApi.HttpCreateUrlGroup(
                    m_ServerSessionHandle.DangerousGetServerSessionId(), &id, 0);

                if (statusCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS) {
                    throw new HttpListenerException((int)statusCode);
                }

                GlobalLog.Assert(id != 0, "Invalid id returned by HttpCreateUrlGroup");
                m_UrlGroupId = id;                

                m_V2Initialized = true;
            }
            catch (Exception exception) {
                //
                // If V2 initialization fails, we mark object as unusable.
                //
                m_State = State.Closed;

                //
                // If Url group or request queue creation failed, close server session before throwing.
                //
                if (m_ServerSessionHandle != null) {
                    m_ServerSessionHandle.Close();
                }
                if (Logging.On) Logging.Exception(Logging.HttpListener, this, "SetupV2Config", exception);
                throw;
            }
        }