示例#1
0
        internal bool RegisterContext(HttpListenerContext context)
        {
            bool flag;

            if (!this._listening)
            {
                return(false);
            }
            if (!context.Authenticate())
            {
                return(false);
            }
            lock (this._ctxRegistrySync)
            {
                if (!this._listening)
                {
                    flag = false;
                }
                else
                {
                    this._ctxRegistry[context] = context;
                    HttpListenerAsyncResult result = this.getAsyncResultFromQueue();
                    if (result == null)
                    {
                        this._ctxQueue.Add(context);
                    }
                    else
                    {
                        result.Complete(context);
                    }
                    flag = true;
                }
            }
            return(flag);
        }
示例#2
0
        private static void complete(HttpListenerAsyncResult asyncResult)
        {
            object obj1 = asyncResult._sync;

            Monitor.Enter(obj1);
            try
            {
                asyncResult._completed = true;
                ManualResetEvent manualResetEvent = asyncResult._waitHandle;
                if (manualResetEvent != null)
                {
                    manualResetEvent.Set();
                }
            }
            finally
            {
                Monitor.Exit(obj1);
            }
            AsyncCallback asyncCallback = asyncResult._callback;

            if (asyncCallback != null)
            {
                ThreadPool.QueueUserWorkItem((object state) => {
                    try
                    {
                        asyncCallback(asyncResult);
                    }
                    catch
                    {
                    }
                }, null);
            }
        }
        private static void complete(HttpListenerAsyncResult asyncResult)
        {
            asyncResult._completed = true;

            var waitHandle = asyncResult._waitHandle;

            if (waitHandle != null)
            {
                waitHandle.Set();
            }

            var callback = asyncResult._callback;

            if (callback != null)
            {
                ThreadPool.QueueUserWorkItem(
                    state => {
                    try {
                        callback(asyncResult);
                    }
                    catch {
                    }
                },
                    null);
            }
        }
        internal HttpListenerAsyncResult BeginGetContext(HttpListenerAsyncResult asyncResult)
        {
            HttpListenerAsyncResult httpListenerAsyncResult;
            object obj = this._ctxRegistrySync;

            Monitor.Enter(obj);
            try
            {
                if (!this._listening)
                {
                    throw new HttpListenerException(995);
                }
                HttpListenerContext contextFromQueue = this.getContextFromQueue();
                if (contextFromQueue != null)
                {
                    asyncResult.Complete(contextFromQueue, true);
                }
                else
                {
                    this._waitQueue.Add(asyncResult);
                }
                httpListenerAsyncResult = asyncResult;
            }
            finally
            {
                Monitor.Exit(obj);
            }
            return(httpListenerAsyncResult);
        }
示例#5
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);
        }
示例#6
0
        public HttpListenerContext GetContext()
        {
            HttpListenerAsyncResult httpListenerAsyncResult = BeginGetContext(new HttpListenerAsyncResult(null, null));

            httpListenerAsyncResult.InGet = true;
            return(EndGetContext(httpListenerAsyncResult));
        }
示例#7
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);
            }
        }
示例#8
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);
        }
示例#9
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);
     }
 }
示例#10
0
        private static void complete(HttpListenerAsyncResult asyncResult)
        {
            asyncResult._completed = true;

            var waitHandle = asyncResult._waitHandle;

            if (waitHandle != null)
            {
                waitHandle.Set();
            }

            var callback = asyncResult._callback;

            /*
             * if (callback != null)
             *    ThreadPool.UnsafeQueueUserWorkItem (
             * state => {
             * try {
             *  callback (asyncResult);
             * }
             * catch {
             * }
             * },
             * null);
             */
        }
示例#11
0
        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);
                }
                else
                {
                    var ctx = _contextQueue.Dequeue();
                    ares.Complete(ctx, true);
                }

                return(ares);
            }
        }
示例#12
0
        private HttpListenerAsyncResult getAsyncResultFromQueue()
        {
            if (this._waitQueue.Count == 0)
            {
                return(null);
            }
            HttpListenerAsyncResult result = this._waitQueue[0];

            this._waitQueue.RemoveAt(0);
            return(result);
        }
示例#13
0
        internal void Complete(Exception exception)
        {
            Exception httpListenerException;

            if (!this._inGet || !(exception is ObjectDisposedException))
            {
                httpListenerException = exception;
            }
            else
            {
                httpListenerException = new HttpListenerException(995, "The listener is closed.");
            }
            this._exception = httpListenerException;
            HttpListenerAsyncResult.complete(this);
        }
        private HttpListenerAsyncResult getAsyncResultFromQueue()
        {
            HttpListenerAsyncResult httpListenerAsyncResult;

            if (this._waitQueue.Count != 0)
            {
                HttpListenerAsyncResult item = this._waitQueue[0];
                this._waitQueue.RemoveAt(0);
                httpListenerAsyncResult = item;
            }
            else
            {
                httpListenerAsyncResult = null;
            }
            return(httpListenerAsyncResult);
        }
示例#15
0
        public HttpListenerContext GetContext()
        {
            this.CheckDisposed();
            if (this._prefixes.Count == 0)
            {
                throw new InvalidOperationException("The listener has no URI prefix on which listens.");
            }
            if (!this._listening)
            {
                throw new InvalidOperationException("The listener hasn't been started.");
            }
            HttpListenerAsyncResult asyncResult = this.BeginGetContext(new HttpListenerAsyncResult(null, null));

            asyncResult.InGet = true;
            return(this.EndGetContext(asyncResult));
        }
示例#16
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);
     }
 }
        private static void complete(HttpListenerAsyncResult asyncResult)
        {
            asyncResult._completed = true;
            asyncResult._waitHandle?.Set();
            AsyncCallback callback = asyncResult._callback;

            if (callback == null)
            {
                return;
            }
            ThreadPool.UnsafeQueueUserWorkItem((WaitCallback) delegate
            {
                try
                {
                    callback(asyncResult);
                }
                catch
                {
                }
            }, (object)null);
        }
示例#18
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);
        }
示例#20
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);
            }
        }
示例#21
0
        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);
        }
示例#22
0
        public HttpListenerContext EndGetContext(IAsyncResult asyncResult)
        {
            this.CheckDisposed();
            if (asyncResult == null)
            {
                throw new ArgumentNullException("asyncResult");
            }
            HttpListenerAsyncResult result = asyncResult as HttpListenerAsyncResult;

            if (result == null)
            {
                throw new ArgumentException("A wrong IAsyncResult.", "asyncResult");
            }
            if (result.EndCalled)
            {
                throw new InvalidOperationException("This IAsyncResult cannot be reused.");
            }
            result.EndCalled = true;
            if (!result.IsCompleted)
            {
                result.AsyncWaitHandle.WaitOne();
            }
            return(result.GetContext());
        }
        private static void complete(HttpListenerAsyncResult asyncResult)
        {
            asyncResult._completed = true;

              var waitHandle = asyncResult._waitHandle;
              if (waitHandle != null)
            waitHandle.Set ();

              var callback = asyncResult._callback;
              //if (callback != null)
              //  ThreadPool.UnsafeQueueUserWorkItem (
              //    state => {
              //      try {
              //        callback (asyncResult);
              //      }
              //      catch {
              //      }
              //    },
              //    null);
              if (callback != null)
              ThreadPool.QueueUserWorkItem(
            state =>
            {
                try
                {
                    callback(asyncResult);
                }
                catch
                {
                }
            },
            null);
        }
    private static void complete (HttpListenerAsyncResult asyncResult)
    {
      lock (asyncResult._sync) {
        asyncResult._completed = true;

        var waitHandle = asyncResult._waitHandle;
        if (waitHandle != null)
          waitHandle.Set ();
      }

      var callback = asyncResult._callback;
      if (callback == null)
        return;

      ThreadPool.QueueUserWorkItem (
        state => {
          try {
            callback (asyncResult);
          }
          catch {
          }
        },
        null
      );
    }
        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;
              }
        }
示例#26
0
 internal void Complete(HttpListenerContext context, bool syncCompleted)
 {
     this._context       = context;
     this._syncCompleted = syncCompleted;
     HttpListenerAsyncResult.complete(this);
 }
 private static void complete(HttpListenerAsyncResult asyncResult)
 {
示例#28
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;
    }