Beispiel #1
0
        internal HttpConnection(Socket socket, EndPointListener listener)
        {
            _socket   = socket;
            _listener = listener;
            _secure   = listener.IsSecure;

            var netStream = new NetworkStream(socket, false);

            if (_secure)
            {
                var conf      = listener.SslConfiguration;
                var sslStream = new SslStream(netStream, false, conf.ClientCertificateValidationCallback);
                sslStream.AuthenticateAsServer(
                    conf.ServerCertificate,
                    conf.ClientCertificateRequired,
                    conf.EnabledSslProtocols,
                    conf.CheckCertificateRevocation);

                _stream = sslStream;
            }
            else
            {
                _stream = netStream;
            }

            _sync    = new object();
            _timeout = 90000; // 90k ms for first request, 15k ms from then on.
            _timer   = new Timer(onTimeout, this, Timeout.Infinite, Timeout.Infinite);

            init();
        }
Beispiel #2
0
        internal static void RemoveEndPoint(EndPointListener listener)
        {
            lock (((ICollection)_addressToEndpoints).SyncRoot) {
                var addr = listener.Address;
                var eps  = _addressToEndpoints[addr];
                eps.Remove(listener.Port);
                if (eps.Count == 0)
                {
                    _addressToEndpoints.Remove(addr);
                }

                listener.Close();
            }
        }
Beispiel #3
0
        private static EndPointListener getEndPointListener(
            HttpListenerPrefix prefix, HttpListener listener
            )
        {
            var addr = convertToIPAddress(prefix.Host);

            Dictionary <int, EndPointListener> eps = null;

            if (_addressToEndpoints.ContainsKey(addr))
            {
                eps = _addressToEndpoints[addr];
            }
            else
            {
                eps = new Dictionary <int, EndPointListener> ();
                _addressToEndpoints[addr] = eps;
            }

            var port = prefix.Port;

            EndPointListener lsnr = null;

            if (eps.ContainsKey(port))
            {
                lsnr = eps[port];
            }
            else
            {
                lsnr =
                    new EndPointListener(
                        addr,
                        port,
                        listener.ReuseAddress,
                        prefix.IsSecure,
                        listener.CertificateFolderPath,
                        listener.SslConfiguration
                        );

                eps[port] = lsnr;
            }

            return(lsnr);
        }
Beispiel #4
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();
            }
        }