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 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();
            }
        }
Beispiel #4
0
        private static EndPointListener getEndPointListener(
            string host, int port, HttpListener listener, bool secure)
        {
            var addr = convertToAddress(host);

            Dictionary <int, EndPointListener> eps = null;

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

            EndPointListener lsnr = null;

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

                eps[port] = lsnr;
            }

            return(lsnr);
        }