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)
#if !DNXCORE50
                { ThreadPool.UnsafeQueueUserWorkItem(InvokeCB, this); }
#else
                { ThreadPool.QueueUserWorkItem(InvokeCB, this); }
#endif
            }
        }
예제 #2
0
        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 early to avoid race conditions
            lock (wait_queue) {
                lock (ctx_queue) {
                    HttpListenerContext ctx = GetContextFromQueue();
                    if (ctx != null)
                    {
                        ares.Complete(ctx, true);
                        return(ares);
                    }
                }

                wait_queue.Add(ares);
            }

            return(ares);
        }
예제 #3
0
        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);
            }
        }