Ejemplo n.º 1
0
 public void Start()
 {
     this.CheckDisposed();
     if (this._listening)
     {
         return;
     }
     EndPointManager.AddListener(this);
     this._listening = true;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Removes all URI prefixes from the collection.
        /// </summary>
        /// <exception cref="ObjectDisposedException">
        /// The <see cref="HttpListener"/> associated with this collection is closed.
        /// </exception>
        public void Clear()
        {
            _listener.CheckDisposed();

            _prefixes.Clear();
            if (_listener.IsListening)
            {
                EndPointManager.RemoveListener(_listener);
            }
        }
Ejemplo n.º 3
0
 public void Stop()
 {
     CheckDisposed();
     if (_listening)
     {
         _listening = false;
         EndPointManager.RemoveListener(this);
         sendServiceUnavailable();
     }
 }
Ejemplo n.º 4
0
 public void Stop()
 {
     this.CheckDisposed();
     if (!this._listening)
     {
         return;
     }
     this._listening = false;
     EndPointManager.RemoveListener(this);
     this.sendServiceUnavailable();
 }
Ejemplo n.º 5
0
        public static void RemoveListener(HttpListener httpListener)
        {
            object syncRoot = ((ICollection)EndPointManager._ipToEndpoints).SyncRoot;

            lock (syncRoot)
            {
                foreach (string uriPrefix in httpListener.Prefixes)
                {
                    EndPointManager.removePrefix(uriPrefix, httpListener);
                }
            }
        }
 public void Add(string uriPrefix)
 {
     this._listener.CheckDisposed();
     HttpListenerPrefix.CheckPrefix(uriPrefix);
     if (!this._prefixes.Contains(uriPrefix))
     {
         this._prefixes.Add(uriPrefix);
         if (this._listener.IsListening)
         {
             EndPointManager.AddPrefix(uriPrefix, this._listener);
         }
     }
 }
Ejemplo n.º 7
0
        public static void AddPrefix(string uriPrefix, WebSocketSharp.Net.HttpListener listener)
        {
            object syncRoot = ((ICollection)EndPointManager._endpoints).SyncRoot;

            Monitor.Enter(syncRoot);
            try
            {
                EndPointManager.addPrefix(uriPrefix, listener);
            }
            finally
            {
                Monitor.Exit(syncRoot);
            }
        }
        /// <summary>
        /// Removes all URI prefixes from the collection.
        /// </summary>
        /// <exception cref="ObjectDisposedException">
        /// The <see cref="HttpListener"/> instance associated with this
        /// collection is closed.
        /// </exception>
        public void Clear()
        {
            if (_listener.IsDisposed)
            {
                throw new ObjectDisposedException(_listener.GetType().ToString());
            }

            if (_listener.IsListening)
            {
                EndPointManager.RemoveListener(_listener);
            }

            _prefixes.Clear();
        }
Ejemplo n.º 9
0
        private void close(bool force)
        {
            EndPointManager.RemoveListener(this);

            lock (_ctxRegistrySync) {
                if (!force)
                {
                    sendServiceUnavailable();
                }
            }

            cleanupContextRegistry();
            cleanupConnections();
            cleanupWaitQueue(new ObjectDisposedException(GetType().ToString()));
        }
Ejemplo n.º 10
0
        public void Add(string uriPrefix)
        {
            listener.CheckDisposed();
            ListenerPrefix.CheckUri(uriPrefix);
            if (prefixes.Contains(uriPrefix))
            {
                return;
            }

            prefixes.Add(uriPrefix);
            if (listener.IsListening)
            {
                EndPointManager.AddPrefix(uriPrefix, listener);
            }
        }
 private void leaveIfNoPrefix()
 {
     if (this._prefixes.Count <= 0)
     {
         List <HttpListenerPrefix> httpListenerPrefixes = this._unhandled;
         if ((httpListenerPrefixes == null ? true : httpListenerPrefixes.Count <= 0))
         {
             httpListenerPrefixes = this._all;
             if ((httpListenerPrefixes == null ? true : httpListenerPrefixes.Count <= 0))
             {
                 EndPointManager.RemoveEndPoint(this._endpoint);
             }
         }
     }
 }
        public bool Remove(string uriPrefix)
        {
            this._listener.CheckDisposed();
            if (uriPrefix == null)
            {
                throw new ArgumentNullException("uriPrefix");
            }
            bool flag = this._prefixes.Remove(uriPrefix);

            if (flag && this._listener.IsListening)
            {
                EndPointManager.RemovePrefix(uriPrefix, this._listener);
            }
            return(flag);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Adds the specified <paramref name="uriPrefix"/> to the collection.
        /// </summary>
        /// <param name="uriPrefix">
        /// A <see cref="string"/> that represents the URI prefix to add. The prefix must be
        /// a well-formed URI prefix with http or https scheme, and must end with a <c>'/'</c>.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="uriPrefix"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="uriPrefix"/> is invalid.
        /// </exception>
        /// <exception cref="ObjectDisposedException">
        /// The <see cref="HttpListener"/> associated with this collection is closed.
        /// </exception>
        public void Add(string uriPrefix)
        {
            _listener.CheckDisposed();
            HttpListenerPrefix.CheckPrefix(uriPrefix);
            if (_prefixes.Contains(uriPrefix))
            {
                return;
            }

            _prefixes.Add(uriPrefix);
            if (_listener.IsListening)
            {
                EndPointManager.AddPrefix(uriPrefix, _listener);
            }
        }
Ejemplo n.º 14
0
        private static void removePrefix(string uriPrefix, HttpListener httpListener)
        {
            ListenerPrefix listenerPrefix = new ListenerPrefix(uriPrefix);

            if (listenerPrefix.Path.IndexOf('%') != -1)
            {
                return;
            }
            if (listenerPrefix.Path.IndexOf("//", StringComparison.Ordinal) != -1)
            {
                return;
            }
            EndPointListener endPointListener = EndPointManager.getEndPointListener(IPAddress.Any, listenerPrefix.Port, httpListener, listenerPrefix.Secure);

            endPointListener.RemovePrefix(listenerPrefix, httpListener);
        }
Ejemplo n.º 15
0
        private static void addPrefix(string uriPrefix, HttpListener httpListener)
        {
            ListenerPrefix listenerPrefix = new ListenerPrefix(uriPrefix);

            if (listenerPrefix.Path.IndexOf('%') != -1)
            {
                throw new HttpListenerException(400, "Invalid path.");
            }
            if (listenerPrefix.Path.IndexOf("//", StringComparison.Ordinal) != -1)
            {
                throw new HttpListenerException(400, "Invalid path.");
            }
            EndPointListener endPointListener = EndPointManager.getEndPointListener(IPAddress.Any, listenerPrefix.Port, httpListener, listenerPrefix.Secure);

            endPointListener.AddPrefix(listenerPrefix, httpListener);
        }
Ejemplo n.º 16
0
 private void checkIfRemove()
 {
     if (this._prefixes.Count > 0)
     {
         return;
     }
     if (this._unhandled != null && this._unhandled.Count > 0)
     {
         return;
     }
     if (this._all != null && this._all.Count > 0)
     {
         return;
     }
     EndPointManager.RemoveEndPoint(this, this._endpoint);
 }
Ejemplo n.º 17
0
 private void close(bool force)
 {
     if (this._listening)
     {
         this._listening = false;
         EndPointManager.RemoveListener(this);
     }
     lock (this._ctxRegistrySync)
     {
         this.cleanupContextQueue(!force);
     }
     this.cleanupContextRegistry();
     this.cleanupConnections();
     this.cleanupWaitQueue(new ObjectDisposedException(base.GetType().ToString()));
     this._disposed = true;
 }
Ejemplo n.º 18
0
 public void Stop()
 {
     this.CheckDisposed();
     if (this._listening)
     {
         this._listening = false;
         EndPointManager.RemoveListener(this);
         lock (this._ctxRegistrySync)
         {
             this.cleanupContextQueue(true);
         }
         this.cleanupContextRegistry();
         this.cleanupConnections();
         this.cleanupWaitQueue(new HttpListenerException(0x3e3, "The listener is stopped."));
     }
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Removes the specified <paramref name="uriPrefix"/> from the collection.
        /// </summary>
        /// <returns>
        /// <c>true</c> if <paramref name="uriPrefix"/> is successfully found and removed;
        /// otherwise, <c>false</c>.
        /// </returns>
        /// <param name="uriPrefix">
        /// A <see cref="string"/> that represents the URI prefix to remove.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="uriPrefix"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ObjectDisposedException">
        /// The <see cref="HttpListener"/> associated with this collection is closed.
        /// </exception>
        public bool Remove(string uriPrefix)
        {
            _listener.CheckDisposed();
            if (uriPrefix == null)
            {
                throw new ArgumentNullException("uriPrefix");
            }

            var ret = _prefixes.Remove(uriPrefix);

            if (ret && _listener.IsListening)
            {
                EndPointManager.RemovePrefix(uriPrefix, _listener);
            }

            return(ret);
        }
Ejemplo n.º 20
0
        private void checkIfRemove()
        {
            if (_prefixes.Count > 0)
            {
                return;
            }
            List <HttpListenerPrefix> unhandled = _unhandled;

            if (unhandled == null || unhandled.Count <= 0)
            {
                unhandled = _all;
                if (unhandled == null || unhandled.Count <= 0)
                {
                    EndPointManager.RemoveEndPoint(this);
                }
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Starts receiving incoming requests.
        /// </summary>
        /// <exception cref="ObjectDisposedException">
        /// This listener has been closed.
        /// </exception>
        public void Start()
        {
            CheckDisposed();

            lock (_contextRegistrySync) {
                CheckDisposed();

                if (_listening)
                {
                    return;
                }

                EndPointManager.AddListener(this);

                _listening = true;
            }
        }
Ejemplo n.º 22
0
        public static void RemoveListener(WebSocketSharp.Net.HttpListener listener)
        {
            object syncRoot = ((ICollection)EndPointManager._endpoints).SyncRoot;

            Monitor.Enter(syncRoot);
            try
            {
                foreach (string prefix in listener.Prefixes)
                {
                    EndPointManager.removePrefix(prefix, listener);
                }
            }
            finally
            {
                Monitor.Exit(syncRoot);
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Stops receiving incoming requests.
        /// </summary>
        /// <exception cref="ObjectDisposedException">
        /// This listener has been closed.
        /// </exception>
        public void Stop()
        {
            CheckDisposed();
            if (!_listening)
            {
                return;
            }

            _listening = false;
            EndPointManager.RemoveListener(this);

            lock (_ctxRegistrySync)
                cleanupContextQueue(true);

            cleanupContextRegistry();
            cleanupConnections();
            cleanupWaitQueue(new HttpListenerException(995, "The listener is stopped."));
        }
Ejemplo n.º 24
0
        private void close(bool force)
        {
            if (_listening)
            {
                _listening = false;

                cleanupContextQueue(force);
                cleanupContextRegistry();

                var name = GetType().ToString();
                var ex   = new ObjectDisposedException(name);
                cleanupWaitQueue(ex);

                EndPointManager.RemoveListener(this);
            }

            _disposed = true;
        }
Ejemplo n.º 25
0
        private static void addPrefix(string uriPrefix, WebSocketSharp.Net.HttpListener listener)
        {
            int num;
            EndPointListener   endPointListener;
            HttpListenerPrefix httpListenerPrefix = new HttpListenerPrefix(uriPrefix);
            IPAddress          pAddress           = EndPointManager.convertToIPAddress(httpListenerPrefix.Host);

            if (!pAddress.IsLocal())
            {
                throw new WebSocketSharp.Net.HttpListenerException(87, "Includes an invalid host.");
            }
            if (!int.TryParse(httpListenerPrefix.Port, out num))
            {
                throw new WebSocketSharp.Net.HttpListenerException(87, "Includes an invalid port.");
            }
            if (!num.IsPortNumber())
            {
                throw new WebSocketSharp.Net.HttpListenerException(87, "Includes an invalid port.");
            }
            string path = httpListenerPrefix.Path;

            if (path.IndexOf('%') != -1)
            {
                throw new WebSocketSharp.Net.HttpListenerException(87, "Includes an invalid path.");
            }
            if (path.IndexOf("//", StringComparison.Ordinal) != -1)
            {
                throw new WebSocketSharp.Net.HttpListenerException(87, "Includes an invalid path.");
            }
            IPEndPoint pEndPoint = new IPEndPoint(pAddress, num);

            if (!EndPointManager._endpoints.TryGetValue(pEndPoint, out endPointListener))
            {
                endPointListener = new EndPointListener(pEndPoint, httpListenerPrefix.IsSecure, listener.CertificateFolderPath, listener.SslConfiguration, listener.ReuseAddress);
                EndPointManager._endpoints.Add(pEndPoint, endPointListener);
            }
            else if (endPointListener.IsSecure ^ httpListenerPrefix.IsSecure)
            {
                throw new WebSocketSharp.Net.HttpListenerException(87, "Includes an invalid scheme.");
            }
            endPointListener.AddPrefix(httpListenerPrefix, listener);
        }
        /// <summary>
        /// Adds the specified URI prefix to the collection.
        /// </summary>
        /// <param name="uriPrefix">
        ///   <para>
        ///   A <see cref="string"/> that specifies the URI prefix to add.
        ///   </para>
        ///   <para>
        ///   It must be a well-formed URI prefix with http or https scheme,
        ///   and must end with a '/'.
        ///   </para>
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="uriPrefix"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="uriPrefix"/> is invalid.
        /// </exception>
        /// <exception cref="ObjectDisposedException">
        /// The <see cref="HttpListener"/> instance associated with this
        /// collection is closed.
        /// </exception>
        public void Add(string uriPrefix)
        {
            if (_listener.IsDisposed)
            {
                throw new ObjectDisposedException(_listener.GetType().ToString());
            }

            HttpListenerPrefix.CheckPrefix(uriPrefix);

            if (_prefixes.Contains(uriPrefix))
            {
                return;
            }

            if (_listener.IsListening)
            {
                EndPointManager.AddPrefix(uriPrefix, _listener);
            }

            _prefixes.Add(uriPrefix);
        }
        /// <summary>
        /// Removes the specified URI prefix from the collection.
        /// </summary>
        /// <returns>
        /// <c>true</c> if the URI prefix is successfully removed; otherwise,
        /// <c>false</c>.
        /// </returns>
        /// <param name="uriPrefix">
        /// A <see cref="string"/> that specifies the URI prefix to remove.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="uriPrefix"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ObjectDisposedException">
        /// The <see cref="HttpListener"/> instance associated with this
        /// collection is closed.
        /// </exception>
        public bool Remove(string uriPrefix)
        {
            _listener.CheckDisposed();

            if (uriPrefix == null)
            {
                throw new ArgumentNullException("uriPrefix");
            }

            if (!_prefixes.Contains(uriPrefix))
            {
                return(false);
            }

            if (_listener.IsListening)
            {
                EndPointManager.RemovePrefix(uriPrefix, _listener);
            }

            return(_prefixes.Remove(uriPrefix));
        }
Ejemplo n.º 28
0
        private void leaveIfNoPrefix()
        {
            if (_prefixes.Count > 0)
            {
                return;
            }

            var prefs = _unhandled;

            if (prefs != null && prefs.Count > 0)
            {
                return;
            }

            prefs = _all;
            if (prefs != null && prefs.Count > 0)
            {
                return;
            }

            EndPointManager.RemoveEndPoint(_endpoint);
        }
Ejemplo n.º 29
0
        void CheckIfRemove()
        {
            if (prefixes.Count > 0)
            {
                return;
            }

            var list = unhandled;

            if (list != null && list.Count > 0)
            {
                return;
            }

            list = all;
            if (list != null && list.Count > 0)
            {
                return;
            }

            EndPointManager.RemoveEndPoint(this, endpoint);
        }
Ejemplo n.º 30
0
        private void close(bool force)
        {
            if (!_listening)
            {
                _disposed = true;

                return;
            }

            _listening = false;

            cleanupContextQueue(force);
            cleanupContextRegistry();

            var msg = "The listener is closed.";

            cleanupWaitQueue(msg);

            EndPointManager.RemoveListener(this);

            _disposed = true;
        }