internal void Complete(Exception exc) { #if AUTHENTICATION if (_forward != null) { _forward.Complete(exc); return; } #endif _exception = exc; if (InGet && (exc is ObjectDisposedException)) { _exception = new HttpListenerException(500, "Listener closed"); } lock (_locker) { _completed = true; _handle?.Set(); if (_cb != null) { ThreadPool.QueueUserWorkItem(_invokeCb, this); } } }
/// <summary> /// Begins the asynchronous operation of retrieving an HTTP conext /// </summary> /// <param name="callback">The callback.</param> /// <param name="state">The state.</param> /// <returns></returns> /// <exception cref="System.InvalidOperationException">Please, call Start before using this method.</exception> public IAsyncResult BeginGetContext(AsyncCallback callback, object state) { CheckDisposed(); if (!IsListening) { throw new InvalidOperationException("Please, call Start before using this method."); } var ares = new ListenerAsyncResult(callback, state); // lock wait_queue early to avoid race conditions lock (_waitQueue) { lock (_ctxQueue) { var ctx = GetContextFromQueue(); if (ctx != null) { ares.Complete(ctx, true); return(ares); } } _waitQueue.Add(ares); } return(ares); }
internal void RegisterContext(HttpListenerContext context) { lock (_registry) _registry[context] = context; ListenerAsyncResult ares = null; lock (_waitQueue) { if (_waitQueue.Count == 0) { lock (_ctxQueue) _ctxQueue.Add(context); } else { ares = (ListenerAsyncResult)_waitQueue[0]; _waitQueue.RemoveAt(0); } } ares?.Complete(context); }
/// <summary> /// Begins the asynchronous operation of retrieving an HTTP conext /// </summary> /// <param name="callback">The callback.</param> /// <param name="state">The state.</param> /// <returns></returns> /// <exception cref="System.InvalidOperationException">Please, call Start before using this method.</exception> public IAsyncResult BeginGetContext(AsyncCallback callback, object state) { CheckDisposed(); if (!IsListening) throw new InvalidOperationException("Please, call Start before using this method."); var ares = new ListenerAsyncResult(callback, state); // lock wait_queue early to avoid race conditions lock (_waitQueue) { lock (_ctxQueue) { var ctx = GetContextFromQueue(); if (ctx != null) { ares.Complete(ctx, true); return ares; } } _waitQueue.Add(ares); } return ares; }