internal void Complete(Exception exc) { if (forward != null) { forward.Complete(exc); return; } exception = exc; if (InGet && (exc is ObjectDisposedException)) { exception = new HttpListenerException(500, "Listener closed"); } lock (locker) { completed = true; if (handle != null) { handle.Set(); } if (cb != null) { ThreadPool.UnsafeQueueUserWorkItem(InvokeCB, this); } } }
internal void RegisterContext(HttpListenerContext context) { lock (registry) registry[context] = context; ListenerAsyncResult ares = null; lock (wait_queue) { if (wait_queue.Count == 0) { lock (ctx_queue) ctx_queue.Add(context); } else { ares = (ListenerAsyncResult)wait_queue[0]; wait_queue.RemoveAt(0); } } if (ares != null) { ares.Complete(context); } }
public IAsyncResult BeginGetContext(AsyncCallback callback, Object state) { CheckDisposed(); if (!listening) { throw new InvalidOperationException("Please, call Start before using this method."); } ListenerAsyncResult ares = new ListenerAsyncResult(callback, state); lock (wait_queue) { lock (ctx_queue) { HttpListenerContext ctx = GetContextFromQueue(); if (ctx != null) { ares.Complete(ctx, true); return(ares); } } wait_queue.Add(ares); } return(ares); }