Complete() private method

private Complete ( Exception exception ) : void
exception System.Exception
return void
Ejemplo n.º 1
0
        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);
                }
            }
        }
Ejemplo n.º 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 (((ICollection)wait_queue).SyncRoot) {
                lock (((ICollection)ctx_queue).SyncRoot) {
                    HttpListenerContext ctx = GetContextFromQueue();
                    if (ctx != null)
                    {
                        ares.Complete(ctx, true);
                        return(ares);
                    }
                }

                wait_queue.Add(ares);
            }

            return(ares);
        }
Ejemplo n.º 3
0
        internal void RegisterContext(HttpListenerContext context)
        {
            lock (_ctxRegistrySync)
                _ctxRegistry[context] = context;

            ListenerAsyncResult ares = null;

            lock (_waitQueueSync) {
                if (_waitQueue.Count == 0)
                {
                    lock (_ctxQueueSync)
                        _ctxQueue.Add(context);
                }
                else
                {
                    ares = _waitQueue[0];
                    _waitQueue.RemoveAt(0);
                }
            }

            if (ares != null)
            {
                ares.Complete(context);
            }
        }
Ejemplo n.º 4
0
        internal void RegisterContext(HttpListenerContext context)
        {
            lock (((ICollection)_registry).SyncRoot)
                _registry [context] = context;

            ListenerAsyncResult ares = null;

            lock (((ICollection)_waitQueue).SyncRoot) {
                if (_waitQueue.Count == 0)
                {
                    lock (((ICollection)_contextQueue).SyncRoot)
                        _contextQueue.Add(context);
                }
                else
                {
                    ares = _waitQueue [0];
                    _waitQueue.RemoveAt(0);
                }
            }

            if (ares != null)
            {
                ares.Complete(context);
            }
        }
Ejemplo n.º 5
0
        internal ListenerAsyncResult BeginGetContext(ListenerAsyncResult asyncResult)
        {
            CheckDisposed();
            if (_prefixes.Count == 0)
            {
                throw new InvalidOperationException("The listener has no URI prefix on which listens.");
            }

            if (!_listening)
            {
                throw new InvalidOperationException("The listener hasn't been started.");
            }

            // Lock _waitQueue early to avoid race conditions.
            lock (_waitQueueSync) {
                lock (_ctxQueueSync) {
                    var ctx = getContextFromQueue();
                    if (ctx != null)
                    {
                        asyncResult.Complete(ctx, true);
                        return(asyncResult);
                    }
                }

                _waitQueue.Add(asyncResult);
            }

            return(asyncResult);
        }
Ejemplo n.º 6
0
        internal ListenerAsyncResult BeginGetContext(ListenerAsyncResult asyncResult)
        {
            CheckDisposed();
            if (_prefixes.Count == 0)
            {
                throw new InvalidOperationException("Please, call AddPrefix before using this method.");
            }

            if (!_listening)
            {
                throw new InvalidOperationException("Please, call Start before using this method.");
            }

            // Lock _waitQueue early to avoid race conditions.
            lock (((ICollection)_waitQueue).SyncRoot) {
                lock (((ICollection)_contextQueue).SyncRoot) {
                    var context = getContextFromQueue();
                    if (context != null)
                    {
                        asyncResult.Complete(context, true);
                        return(asyncResult);
                    }
                }

                _waitQueue.Add(asyncResult);
            }

            return(asyncResult);
        }
Ejemplo n.º 7
0
        internal void RegisterContext(HttpListenerContext context)
        {
            object syncRoot = ((ICollection)this._registry).SyncRoot;

            lock (syncRoot)
            {
                this._registry[context] = context;
            }
            ListenerAsyncResult listenerAsyncResult = null;
            object syncRoot2 = ((ICollection)this._waitQueue).SyncRoot;

            lock (syncRoot2)
            {
                if (this._waitQueue.Count == 0)
                {
                    object syncRoot3 = ((ICollection)this._contextQueue).SyncRoot;
                    lock (syncRoot3)
                    {
                        this._contextQueue.Add(context);
                    }
                }
                else
                {
                    listenerAsyncResult = this._waitQueue[0];
                    this._waitQueue.RemoveAt(0);
                }
            }
            if (listenerAsyncResult != null)
            {
                listenerAsyncResult.Complete(context);
            }
        }
Ejemplo n.º 8
0
        internal ListenerAsyncResult BeginGetContext(ListenerAsyncResult asyncResult)
        {
            this.CheckDisposed();
            if (this._prefixes.Count == 0)
            {
                throw new InvalidOperationException("Please, call AddPrefix before using this method.");
            }
            if (!this._listening)
            {
                throw new InvalidOperationException("Please, call Start before using this method.");
            }
            object syncRoot = ((ICollection)this._waitQueue).SyncRoot;

            lock (syncRoot)
            {
                object syncRoot2 = ((ICollection)this._contextQueue).SyncRoot;
                lock (syncRoot2)
                {
                    HttpListenerContext contextFromQueue = this.getContextFromQueue();
                    if (contextFromQueue != null)
                    {
                        asyncResult.Complete(contextFromQueue, true);
                        return(asyncResult);
                    }
                }
                this._waitQueue.Add(asyncResult);
            }
            return(asyncResult);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Begins getting an incoming request information asynchronously.
        /// </summary>
        /// <remarks>
        /// This asynchronous operation must be completed by calling the <see cref="EndGetContext"/> method.
        /// Typically, the method is invoked by the <paramref name="callback"/> delegate.
        /// </remarks>
        /// <returns>
        /// An <see cref="IAsyncResult"/> that contains the status of the asynchronous operation.
        /// </returns>
        /// <param name="callback">
        /// An <see cref="AsyncCallback"/> delegate that references the method(s)
        /// called when the asynchronous operation completes.
        /// </param>
        /// <param name="state">
        /// An <see cref="object"/> that contains a user defined object to pass to the <paramref name="callback"/> delegate.
        /// </param>
        /// <exception cref="ObjectDisposedException">
        /// This object has been closed.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// The <see cref="HttpListener"/> has not been started or is stopped currently.
        /// </exception>
        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 (((ICollection)wait_queue).SyncRoot) {
                lock (((ICollection)ctx_queue).SyncRoot) {
                    HttpListenerContext ctx = GetContextFromQueue ();
                    if (ctx != null) {
                        ares.Complete (ctx, true);
                        return ares;
                    }
                }

                wait_queue.Add (ares);
            }

            return ares;
        }
Ejemplo n.º 10
0
        internal ListenerAsyncResult BeginGetContext(ListenerAsyncResult asyncResult)
        {
            CheckDisposed ();
              if (_prefixes.Count == 0)
            throw new InvalidOperationException ("The listener has no URI prefix on which listens.");

              if (!_listening)
            throw new InvalidOperationException ("The listener hasn't been started.");

              // Lock _waitQueue early to avoid race conditions.
              lock (_waitQueueSync) {
            lock (_ctxQueueSync) {
              var ctx = getContextFromQueue ();
              if (ctx != null) {
            asyncResult.Complete (ctx, true);
            return asyncResult;
              }
            }

            _waitQueue.Add (asyncResult);
              }

              return asyncResult;
        }
Ejemplo n.º 11
0
    internal ListenerAsyncResult BeginGetContext (ListenerAsyncResult asyncResult)
    {
      CheckDisposed ();
      if (_prefixes.Count == 0)
        throw new InvalidOperationException (
          "Please, call AddPrefix before using this method.");

      if (!_listening)
        throw new InvalidOperationException (
          "Please, call Start before using this method.");

      // Lock _waitQueue early to avoid race conditions
      lock (((ICollection) _waitQueue).SyncRoot) {
        lock (((ICollection) _contextQueue).SyncRoot) {
          var context = getContextFromQueue ();
          if (context != null) {
            asyncResult.Complete (context, true);
            return asyncResult;
          }
        }

        _waitQueue.Add (asyncResult);
      }

      return asyncResult;
    }