Esempio n. 1
0
        public HttpListenerContext EndGetContext(IAsyncResult asyncResult)
        {
            CheckDisposed();
            if (asyncResult == null)
            {
                throw new ArgumentNullException("asyncResult");
            }

            ListenerAsyncResult ares = asyncResult as ListenerAsyncResult;

            if (ares == null)
            {
                throw new ArgumentException("Wrong IAsyncResult.", "asyncResult");
            }

            if (!ares.IsCompleted)
            {
                ares.AsyncWaitHandle.WaitOne();
            }

            lock (wait_queue) {
                int idx = wait_queue.IndexOf(ares);
                if (idx >= 0)
                {
                    wait_queue.RemoveAt(idx);
                }
            }

            HttpListenerContext context = ares.GetContext();

            context.ParseAuthentication(SelectAuthenticationScheme(context));
            return(context);            // This will throw on error.
        }
        /// <summary>Completes an asynchronous operation to retrieve an incoming client request.</summary>
        /// <returns>An <see cref="T:System.Net.HttpListenerContext" /> object that represents the client request.</returns>
        /// <param name="asyncResult">An <see cref="T:System.IAsyncResult" /> object that was obtained when the asynchronous operation was started.</param>
        /// <exception cref="T:System.ArgumentException">
        ///   <paramref name="asyncResult" /> was not obtained by calling the <see cref="M:System.Net.HttpListener.BeginGetContext(System.AsyncCallback,System.Object)" /> method.</exception>
        /// <exception cref="T:System.ArgumentNullException">
        ///   <paramref name="asyncResult" /> is null.</exception>
        /// <exception cref="T:System.InvalidOperationException">The <see cref="M:System.Net.HttpListener.EndGetContext(System.IAsyncResult)" /> method was already called for the specified <paramref name="asyncResult" /> object.</exception>
        /// <exception cref="T:System.ObjectDisposedException">This object is closed.</exception>
        public HttpListenerContext EndGetContext(IAsyncResult asyncResult)
        {
            this.CheckDisposed();
            if (asyncResult == null)
            {
                throw new ArgumentNullException("asyncResult");
            }
            ListenerAsyncResult listenerAsyncResult = asyncResult as ListenerAsyncResult;

            if (listenerAsyncResult == null)
            {
                throw new ArgumentException("Wrong IAsyncResult.", "asyncResult");
            }
            if (!listenerAsyncResult.IsCompleted)
            {
                listenerAsyncResult.AsyncWaitHandle.WaitOne();
            }
            ArrayList obj = this.wait_queue;

            lock (obj)
            {
                int num = this.wait_queue.IndexOf(listenerAsyncResult);
                if (num >= 0)
                {
                    this.wait_queue.RemoveAt(num);
                }
            }
            HttpListenerContext context = listenerAsyncResult.GetContext();

            if (this.auth_schemes != AuthenticationSchemes.Anonymous)
            {
                context.ParseAuthentication(this.auth_schemes);
            }
            return(context);
        }
Esempio n. 3
0
 internal HttpListenerContext GetContext()
 {
     if (forward != null)
     {
         return(forward.GetContext());
     }
     if (exception != null)
     {
         throw exception;
     }
     return(context);
 }
        internal HttpListenerContext GetContext()
        {
            if (_forward != null)
            {
                return(_forward.GetContext());
            }

            if (_exception != null)
            {
                ExceptionDispatchInfo.Throw(_exception);
            }

            return(_context);
        }
Esempio n. 5
0
        public HttpListenerContext EndGetContext(IAsyncResult asyncResult)
        {
            CheckDisposed();
            if (asyncResult == null)
            {
                throw new ArgumentNullException(nameof(asyncResult));
            }

            ListenerAsyncResult ares = asyncResult as ListenerAsyncResult;

            if (ares == null)
            {
                throw new ArgumentException(SR.net_io_invalidasyncresult, nameof(asyncResult));
            }
            if (ares._endCalled)
            {
                throw new InvalidOperationException(SR.Format(SR.net_io_invalidendcall, nameof(EndGetContext)));
            }

            ares._endCalled = true;

            if (!ares.IsCompleted)
            {
                ares.AsyncWaitHandle.WaitOne();
            }

            lock ((_asyncWaitQueue as ICollection).SyncRoot)
            {
                int idx = _asyncWaitQueue.IndexOf(ares);
                if (idx >= 0)
                {
                    _asyncWaitQueue.RemoveAt(idx);
                }
            }

            HttpListenerContext context = ares.GetContext();

            context.ParseAuthentication(SelectAuthenticationScheme(context));

            return(context);
        }