Explicit refcounting removed from connection object
[invirt/third/libt4.git] / rpc / rpctest.cc
index b90d19a..723df82 100644 (file)
@@ -15,7 +15,7 @@ char log_thread_prefix = 'r';
 rpcs *server;  // server rpc object
 rpcc *clients[NUM_CL];  // client rpc object
 string dst; //server's ip address
 rpcs *server;  // server rpc object
 rpcc *clients[NUM_CL];  // client rpc object
 string dst; //server's ip address
-int port;
+in_port_t port;
 
 // server-side handlers. they must be methods of some class
 // to simplify rpcs::reg(). a server process can have handlers
 
 // server-side handlers. they must be methods of some class
 // to simplify rpcs::reg(). a server process can have handlers
@@ -52,7 +52,7 @@ srv::handle_fast(int &r, const int a)
 int
 srv::handle_slow(int &r, const int a)
 {
 int
 srv::handle_slow(int &r, const int a)
 {
-    usleep(random() % 5000);
+    usleep(random() % 500);
     r = a + 2;
     return 0;
 }
     r = a + 2;
     return 0;
 }
@@ -68,7 +68,7 @@ srv service;
 
 void startserver()
 {
 
 void startserver()
 {
-    server = new rpcs((unsigned int)port);
+    server = new rpcs(port);
     server->reg(22, &srv::handle_22, &service);
     server->reg(23, &srv::handle_fast, &service);
     server->reg(24, &srv::handle_slow, &service);
     server->reg(22, &srv::handle_22, &service);
     server->reg(23, &srv::handle_fast, &service);
     server->reg(24, &srv::handle_slow, &service);
@@ -166,7 +166,7 @@ client3(void *xx)
 
     for(int i = 0; i < 4; i++){
         int rep = 0;
 
     for(int i = 0; i < 4; i++){
         int rep = 0;
-        int ret = c->call_timeout(24, rpcc::to(3000), rep, i);
+        int ret = c->call_timeout(24, milliseconds(300), rep, i);
         VERIFY(ret == rpc_const::timeout_failure || rep == i+2);
     }
 }
         VERIFY(ret == rpc_const::timeout_failure || rep == i+2);
     }
 }
@@ -187,14 +187,14 @@ simple_tests(rpcc *c)
     cout << "   -- string concat RPC .. ok" << endl;
 
     // small request, big reply (perhaps req via UDP, reply via TCP)
     cout << "   -- string concat RPC .. ok" << endl;
 
     // small request, big reply (perhaps req via UDP, reply via TCP)
-    intret = c->call_timeout(25, rpcc::to(200000), rep, 70000);
+    intret = c->call_timeout(25, milliseconds(20000), rep, 70000);
     VERIFY(intret == 0);
     VERIFY(rep.size() == 70000);
     cout << "   -- small request, big reply .. ok" << endl;
 
     // specify a timeout value to an RPC that should succeed (udp)
     int xx = 0;
     VERIFY(intret == 0);
     VERIFY(rep.size() == 70000);
     cout << "   -- small request, big reply .. ok" << endl;
 
     // specify a timeout value to an RPC that should succeed (udp)
     int xx = 0;
-    intret = c->call_timeout(23, rpcc::to(3000), xx, 77);
+    intret = c->call_timeout(23, milliseconds(300), xx, 77);
     VERIFY(intret == 0 && xx == 78);
     cout << "   -- no spurious timeout .. ok" << endl;
 
     VERIFY(intret == 0 && xx == 78);
     cout << "   -- no spurious timeout .. ok" << endl;
 
@@ -202,7 +202,7 @@ simple_tests(rpcc *c)
     {
         string arg(1000, 'x');
         string rep2;
     {
         string arg(1000, 'x');
         string rep2;
-        c->call_timeout(22, rpcc::to(3000), rep2, arg, (string)"x");
+        c->call_timeout(22, milliseconds(300), rep2, arg, (string)"x");
         VERIFY(rep2.size() == 1001);
         cout << "   -- no spurious timeout .. ok" << endl;
     }
         VERIFY(rep2.size() == 1001);
         cout << "   -- no spurious timeout .. ok" << endl;
     }
@@ -217,7 +217,7 @@ simple_tests(rpcc *c)
     string non_existent = "127.0.0.1:7661";
     rpcc *c1 = new rpcc(non_existent);
     time_t t0 = time(0);
     string non_existent = "127.0.0.1:7661";
     rpcc *c1 = new rpcc(non_existent);
     time_t t0 = time(0);
-    intret = c1->bind(rpcc::to(3000));
+    intret = c1->bind(milliseconds(300));
     time_t t1 = time(0);
     VERIFY(intret < 0 && (t1 - t0) <= 4);
     cout << "   -- rpc timeout .. ok" << endl;
     time_t t1 = time(0);
     VERIFY(intret < 0 && (t1 - t0) <= 4);
     cout << "   -- rpc timeout .. ok" << endl;
@@ -285,7 +285,7 @@ failure_test()
     delete server;
 
     client1 = new rpcc(dst);
     delete server;
 
     client1 = new rpcc(dst);
-    VERIFY (client1->bind(rpcc::to(3000)) < 0);
+    VERIFY (client1->bind(milliseconds(3000)) < 0);
     cout << "   -- create new client and try to bind to failed server .. failed ok" << endl;
 
     delete client1;
     cout << "   -- create new client and try to bind to failed server .. failed ok" << endl;
 
     delete client1;
@@ -371,7 +371,7 @@ main(int argc, char *argv[])
                 debug_level = atoi(optarg);
                 break;
             case 'p':
                 debug_level = atoi(optarg);
                 break;
             case 'p':
-                port = atoi(optarg);
+                port = (in_port_t)atoi(optarg);
                 break;
             case 'l':
                 VERIFY(setenv("RPC_LOSSY", "5", 1) == 0);
                 break;
             case 'l':
                 VERIFY(setenv("RPC_LOSSY", "5", 1) == 0);
@@ -425,6 +425,6 @@ main(int argc, char *argv[])
     }
 
     while (1) {
     }
 
     while (1) {
-        sleep(1);
+        usleep(100000);
     }
 }
     }
 }