Esempio n. 1
0
        private static void processAccepted(Socket socket, EndPointListener listener)
        {
            HttpConnection conn = null;

            try {
                conn = new HttpConnection(socket, listener);
                lock (listener._unregisteredSync)
                    listener._unregistered[conn] = conn;

                conn.BeginReadRequest();
            }
            catch {
                if (conn != null)
                {
                    conn.Close(true);
                    return;
                }

                socket.Close();
            }
        }
        private static void addPrefix(string uriPrefix, HttpListener listener)
        {
            var pref = new HttpListenerPrefix(uriPrefix);

            var addr = convertToIPAddress(pref.Host);

            if (!addr.IsLocal())
            {
                throw new HttpListenerException(87, "Includes an invalid host.");
            }

            int port;

            if (!Int32.TryParse(pref.Port, out port))
            {
                throw new HttpListenerException(87, "Includes an invalid port.");
            }

            if (!port.IsPortNumber())
            {
                throw new HttpListenerException(87, "Includes an invalid port.");
            }

            var path = pref.Path;

            if (path.IndexOf('%') != -1)
            {
                throw new HttpListenerException(87, "Includes an invalid path.");
            }

            if (path.IndexOf("//", StringComparison.Ordinal) != -1)
            {
                throw new HttpListenerException(87, "Includes an invalid path.");
            }

            var endpoint = new IPEndPoint(addr, port);

            EndPointListener lsnr;

            if (_endpoints.TryGetValue(endpoint, out lsnr))
            {
                if (lsnr.IsSecure ^ pref.IsSecure)
                {
                    throw new HttpListenerException(87, "Includes an invalid scheme.");
                }
            }
            else
            {
                lsnr =
                    new EndPointListener(
                        endpoint,
                        pref.IsSecure,
                        listener.CertificateFolderPath,
                        listener.SslConfiguration,
                        listener.ReuseAddress
                        );

                _endpoints.Add(endpoint, lsnr);
            }

            lsnr.AddPrefix(pref, listener);
        }