Beispiel #1
0
        internal void RegisterContext(HttpListenerContext context)
        {
            lock (_ctxRegistrySync)
            {
                _ctxRegistry[context] = context;
            }
            HttpListenerAsyncResult httpListenerAsyncResult = null;

            lock (_waitQueueSync)
            {
                if (_waitQueue.Count == 0)
                {
                    lock (_ctxQueueSync)
                    {
                        _ctxQueue.Add(context);
                    }
                }
                else
                {
                    httpListenerAsyncResult = _waitQueue[0];
                    _waitQueue.RemoveAt(0);
                }
            }
            httpListenerAsyncResult?.Complete(context);
        }
Beispiel #2
0
 internal HttpListenerAsyncResult BeginGetContext(HttpListenerAsyncResult 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 (_waitQueueSync)
     {
         lock (_ctxQueueSync)
         {
             HttpListenerContext contextFromQueue = getContextFromQueue();
             if (contextFromQueue != null)
             {
                 asyncResult.Complete(contextFromQueue, syncCompleted: true);
                 return(asyncResult);
             }
         }
         _waitQueue.Add(asyncResult);
         return(asyncResult);
     }
 }
Beispiel #3
0
        internal void RegisterContext(HttpListenerContext context)
        {
            lock (_ctxRegistrySync)
                _ctxRegistry[context] = context;

            HttpListenerAsyncResult 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);
            }
        }
Beispiel #4
0
        internal HttpListenerAsyncResult BeginGetContext(HttpListenerAsyncResult 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);
        }
Beispiel #5
0
        private HttpListenerAsyncResult beginGetContext(
            AsyncCallback callback, object state
            )
        {
            lock (_contextRegistrySync)
            {
                if (!_listening)
                {
                    throw new HttpListenerException(995);
                }

                var ares = new HttpListenerAsyncResult(callback, state);

                if (_contextQueue.Count == 0)
                {
                    _waitQueue.Enqueue(ares);
                }
                else
                {
                    var ctx = _contextQueue.Dequeue();
                    ares.Complete(ctx, true);
                }

                return(ares);
            }
        }
        private HttpListenerAsyncResult beginGetContext(
            AsyncCallback callback, object state
            )
        {
            lock (_contextRegistrySync) {
                if (!_listening)
                {
                    var msg = _disposed
                    ? "The listener is closed."
                    : "The listener is stopped.";

                    throw new HttpListenerException(995, msg);
                }

                var ares = new HttpListenerAsyncResult(callback, state);

                if (_contextQueue.Count == 0)
                {
                    _waitQueue.Enqueue(ares);

                    return(ares);
                }

                var ctx = _contextQueue.Dequeue();
                ares.Complete(ctx, true);

                return(ares);
            }
        }
Beispiel #7
0
 internal HttpListenerAsyncResult BeginGetContext(HttpListenerAsyncResult asyncResult)
 {
     lock (this._ctxRegistrySync)
     {
         if (!this._listening)
         {
             throw new HttpListenerException(0x3e3);
         }
         HttpListenerContext context = this.getContextFromQueue();
         if (context == null)
         {
             this._waitQueue.Add(asyncResult);
         }
         else
         {
             asyncResult.Complete(context, true);
         }
         return(asyncResult);
     }
 }
Beispiel #8
0
        internal HttpListenerAsyncResult BeginGetContext(HttpListenerAsyncResult asyncResult)
        {
            lock (_ctxRegistrySync) {
                if (!_listening)
                {
                    throw new HttpListenerException(995);
                }

                var ctx = getContextFromQueue();
                if (ctx == null)
                {
                    _waitQueue.Add(asyncResult);
                }
                else
                {
                    asyncResult.Complete(ctx, true);
                }

                return(asyncResult);
            }
        }
        internal bool RegisterContext(HttpListenerContext context)
        {
            bool flag;

            if (this._listening)
            {
                object obj = this._ctxRegistrySync;
                Monitor.Enter(obj);
                try
                {
                    if (this._listening)
                    {
                        this._ctxRegistry[context] = context;
                        HttpListenerAsyncResult asyncResultFromQueue = this.getAsyncResultFromQueue();
                        if (asyncResultFromQueue != null)
                        {
                            asyncResultFromQueue.Complete(context);
                        }
                        else
                        {
                            this._ctxQueue.Add(context);
                        }
                        flag = true;
                    }
                    else
                    {
                        flag = false;
                    }
                }
                finally
                {
                    Monitor.Exit(obj);
                }
            }
            else
            {
                flag = false;
            }
            return(flag);
        }
Beispiel #10
0
        internal HttpListenerAsyncResult BeginGetContext(
            HttpListenerAsyncResult asyncResult
            )
        {
            lock (_contextRegistrySync) {
                if (!_listening)
                {
                    throw new HttpListenerException(995);
                }

                if (_contextQueue.Count == 0)
                {
                    _waitQueue.Enqueue(asyncResult);
                }
                else
                {
                    var ctx = _contextQueue.Dequeue();
                    asyncResult.Complete(ctx, true);
                }

                return(asyncResult);
            }
        }
        internal bool RegisterContext(HttpListenerContext context)
        {
            if (!_listening)
            {
                return(false);
            }

            HttpListenerAsyncResult ares = null;

            lock (_ctxRegistrySync) {
                if (!_listening)
                {
                    return(false);
                }

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

            if (ares != null)
            {
                ares.Complete(context);
            }

            return(true);
        }
Beispiel #12
0
    internal HttpListenerAsyncResult BeginGetContext (HttpListenerAsyncResult 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;
    }
        internal HttpListenerAsyncResult BeginGetContext(HttpListenerAsyncResult asyncResult)
        {
            lock (_ctxRegistrySync) {
            if (!_listening)
              throw new HttpListenerException (995);

            var ctx = getContextFromQueue ();
            if (ctx == null)
              _waitQueue.Add (asyncResult);
            else
              asyncResult.Complete (ctx, true);

            return asyncResult;
              }
        }