Exemplo n.º 1
0
        public void Test_Ops()
        {
            SocketWatcher w = new SocketWatcher(20);
            Address a = new Address("127.0.0.1", 7002);
            a.Resolve();
            AsyncSocket one = w.CreateListenSocket(this, a);
            AsyncSocket two = null;
            AsyncSocket three = one;
            AsyncSocket four = two;
            Assert.IsTrue(one == three);
            Assert.IsTrue(two == four);
            Assert.IsTrue(one >= three);
            Assert.IsTrue(two >= four);
            Assert.IsTrue(one <= three);
            Assert.IsTrue(two <= four);
            Assert.IsTrue(one != two);
            Assert.IsTrue(two != one);
            Assert.IsTrue(one > two);
            Assert.IsTrue(one >= two);
            Assert.IsTrue(two < one);
            Assert.IsTrue(two <= one);

            two = w.CreateListenSocket(this, a);
            four = two;
            Assert.IsTrue(one == three);
            Assert.IsTrue(two == four);
            Assert.IsTrue(one >= three);
            Assert.IsTrue(two >= four);
            Assert.IsTrue(one <= three);
            Assert.IsTrue(two <= four);
            Assert.IsTrue(one != two);
            Assert.IsTrue(two != one);

            int c = ((IComparable)one).CompareTo(two);
            Assert.IsTrue(c != 0);
            if (c == -1)
            {
                // one less than two
                Assert.IsTrue(one < two);
                Assert.IsTrue(one <= two);
                Assert.IsTrue(two > one);
                Assert.IsTrue(two >= one);
            }
            else if (c == 1)
            {
                // one greater than two
                Assert.IsTrue(one > two);
                Assert.IsTrue(one >= two);
                Assert.IsTrue(two < one);
                Assert.IsTrue(two <= one);
            }
            else
            {
                Assert.IsTrue(false);
            }
            one.Close();
            two.Close();
        }
Exemplo n.º 2
0
        [Test] public void Test_Write()
        {
            SocketWatcher w = new SocketWatcher(20);
            Address a = new Address("127.0.0.1", 7001);
            a.Resolve();

            AsyncSocket listen = w.CreateListenSocket(this, a);
            listen.RequestAccept();

            AsyncSocket connect;
            lock (done)
            {
                connect = w.CreateConnectSocket(this, a);
                bool NoTimeout = Monitor.Wait(done, new TimeSpan(0, 0, 30));

                Assert.IsTrue(NoTimeout, "The read command didn't complete in time.");
                Assert.IsTrue(succeeded, errorMessage);
            }

            Assert.AreEqual("5678901234", success);
            connect.Close();
            listen.Close();
        }
Exemplo n.º 3
0
        public void Test_Full_Response()
        {
            SocketWatcher watcher = new SocketWatcher();
            Address a = new Address("127.0.0.1", 7002);
            a.Resolve();

            ServerListener server = new ServerListener();
            AsyncSocket server_sock = watcher.CreateListenSocket(server, a);
            server_sock.RequestAccept();

            ResponseListener resp = new ResponseListener();
            HttpSocket sock = new HttpSocket(resp);

            Uri u = new Uri("http://localhost:7002/");
            byte[] buf = ENC.GetBytes("11111");
            HttpSocket s = (HttpSocket)sock;
            s.Execute("GET", u, buf, 0, buf.Length, "text/plain");
            resp.Event.WaitOne();
            Assert.AreEqual("1234567890", resp.Last);

            resp.Last = null;
            buf = ENC.GetBytes("22222");
            s.Execute("GET", u, buf, 0, buf.Length, "text/plain");
            resp.Event.WaitOne();
            Assert.AreEqual("1234567890", resp.Last);

            resp.Last = null;
            buf = ENC.GetBytes("33333");
            s.Execute("GET", u, buf, 0, buf.Length, "text/plain");
            resp.Event.WaitOne();
            Assert.AreEqual("12345678901234567890", resp.Last);
        }
Exemplo n.º 4
0
        private void Server()
        {
            SocketWatcher s_w = new SocketWatcher(20);

            //s_w.RequireClientCert = true;

            X509Certificate2 c2;
            X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
            store.Open(OpenFlags.ReadWrite);
            X509Certificate2Collection cert = store.Certificates.Find(X509FindType.FindBySubjectName, "localhost", true);
            if (cert.Count == 0)
            {
                c2 = new X509Certificate2("../../localhost-cert.p12", "test");
                store.Add(c2);
            }
            else
            {
                c2 = cert[0];
            }
            Assert.IsTrue(c2.HasPrivateKey);
            Assert.IsNotNull(c2.PrivateKey);
            Assert.AreEqual(typeof(X509Certificate2), c2.GetType());

            cert = store.Certificates.Find(X509FindType.FindByThumbprint, c2.GetCertHashString(), false);
            c2 = cert[0];
            Assert.AreEqual(typeof(X509Certificate2), c2.GetType());
            Assert.IsTrue(c2.HasPrivateKey);
            Assert.IsNotNull(c2.PrivateKey);
            store.Close();
            s_w.LocalCertificate = c2;
            s_w.Synchronous = true;

            m_listen = s_w.CreateListenSocket(this, a, true);
            lock(start)
            {
                Monitor.Pulse(start);
            }

            try
            {
                m_listen.RequestAccept();
            }
            catch (Exception ex)
            {
                lock (done)
                {
                    succeeded = false;
                    errorMessage = ex.Message;
                    Monitor.Pulse(done);
                }
            }
        }