Esempio n. 1
0
 public static void RemoveEndPoint(EndPointListener epl, IPEndPoint ep)
 {
     lock (ip_to_endpoints) {
         // Dictionary<int, EndPointListener> p
         Hashtable p = null;
         p = (Hashtable)ip_to_endpoints [ep.Address];
         p.Remove(ep.Port);
         epl.Close();
     }
 }
Esempio n. 2
0
        static void RemovePrefixInternal(string prefix, HttpListener listener)
        {
            ListenerPrefix lp = new ListenerPrefix(prefix);

            if (lp.Path.IndexOf('%') != -1)
            {
                return;
            }

            if (lp.Path.IndexOf("//") != -1)
            {
                return;
            }

            EndPointListener epl = GetEPListener(IPAddress.Any, lp.Port, listener, lp.Secure);

            epl.RemovePrefix(lp, listener);
        }
Esempio n. 3
0
        static void AddPrefixInternal(string p, HttpListener listener)
        {
            ListenerPrefix lp = new ListenerPrefix(p);

            if (lp.Path.IndexOf('%') != -1)
            {
                throw new HttpListenerException(400, "Invalid path.");
            }

            if (lp.Path.IndexOf("//") != -1)              // TODO: Code?
            {
                throw new HttpListenerException(400, "Invalid path.");
            }

            // Always listens on all the interfaces, no matter the host name/ip used.
            EndPointListener epl = GetEPListener(IPAddress.Any, lp.Port, listener, lp.Secure);

            epl.AddPrefix(lp, listener);
        }
Esempio n. 4
0
        static void OnAccept(IAsyncResult ares)
        {
            EndPointListener epl      = (EndPointListener)ares.AsyncState;
            Socket           accepted = null;

            try {
                accepted = epl.sock.EndAccept(ares);
            } catch {
                // Anything to do here?
            } finally {
                try {
                    epl.sock.BeginAccept(OnAccept, epl);
                } catch {
                    if (accepted != null)
                    {
                        try {
                            accepted.Close();
                        } catch {}
                        accepted = null;
                    }
                }
            }

            if (accepted == null)
            {
                return;
            }

            if (epl.secure && epl.cert == null)              //(epl.cert == null || epl.key == null)) {
            {
                accepted.Close();
                return;
            }
            HttpConnection conn = new HttpConnection(accepted, epl, epl.secure, epl.cert);             //, epl.key);

            conn.BeginReadRequest();
        }
Esempio n. 5
0
        //AsymmetricAlgorithm key;

        public HttpConnection(Socket sock, EndPointListener epl, bool secure, X509Certificate2 cert)         //, AsymmetricAlgorithm key)
        {
            this.sock   = sock;
            this.epl    = epl;
            this.secure = secure;
            //this.key = key;
            if (secure == false)
            {
                stream = new NetworkStream(sock, false);
            }
            else
            {
#if EMBEDDED_IN_1_0
                throw new NotImplementedException();
#else
                //SslServerStream ssl_stream = new SslServerStream (new NetworkStream (sock, false), cert, false, false);
                //ssl_stream.PrivateKeyCertSelectionDelegate += OnPVKSelection;
                var ssl_stream = new System.Net.Security.SslStream(new NetworkStream(sock, false), true);
                ssl_stream.AuthenticateAsServer(cert);
                stream = ssl_stream;
#endif
            }
            Init();
        }