Ejemplo n.º 1
0
        public static void RemoveEndPoint(EndPointListener epl, IPEndPoint ep)
        {
            lock (IPToEndpoints)
            {
                var p = IPToEndpoints[ep.Address];
                p.Remove(ep.Port);
                if (p.Count == 0)
                {
                    IPToEndpoints.Remove(ep.Address);
                }
            }

            epl.Close();
        }
Ejemplo n.º 2
0
        private static EndPointListener GetEpListener(string host, int port, HttpListener listener, bool secure = false)
        {
            IPAddress addr;

            if (host == "*")
            {
                addr = IPAddress.Any;
            }
            else if (IPAddress.TryParse(host, out addr) == false)
            {
                try
                {
                    var iphost = new IPHostEntry {
                        HostName = host, AddressList = Dns.GetHostAddressesAsync(host).Result
                    };

                    addr = iphost.AddressList[0];
                }
                catch
                {
                    addr = IPAddress.Any;
                }
            }

            Dictionary <int, EndPointListener> p;

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

            EndPointListener epl;

            if (p.ContainsKey(port))
            {
                epl = p[port];
            }
            else
            {
                epl     = new EndPointListener(listener, addr, port, secure);
                p[port] = epl;
            }

            return(epl);
        }
Ejemplo n.º 3
0
        public HttpConnection(Socket sock, EndPointListener epl)
#endif
        {
            _sock = sock;
            _epl  = epl;

#if SSL
            IsSecure = secure;

            if (!secure)
            {
                Stream = new NetworkStream(sock, false);
            }
            else
            {
                _cert = cert;

                ssl_stream = epl.Listener.CreateSslStream(new NetworkStream(sock, false), false, (t, c, ch, e) =>
                {
                    if (c == null)
                    {
                        return(true);
                    }
                    var c2 = c as X509Certificate2;
                    if (c2 == null)
                    {
                        c2 = new X509Certificate2(c.GetRawCertData());
                    }
                    client_cert        = c2;
                    client_cert_errors = new int[] { (int)e };
                    return(true);
                });
                stream = ssl_stream.AuthenticatedStream;
            }
#else
            Stream = new NetworkStream(sock, false);
#endif
            _timer = new Timer(OnTimeout, null, Timeout.Infinite, Timeout.Infinite);
            Init();
        }
Ejemplo n.º 4
0
 public HttpConnection(Socket sock, EndPointListener epl, bool secure, X509Certificate cert)