X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/blobdiff_plain/24bebc0ecf83446c7371eff69042322aab34976a..603bac8fcb3697f283e6537d81b4a92e457ebbad:/rpc/rpctest.cc diff --git a/rpc/rpctest.cc b/rpc/rpctest.cc index 7217b25..2f58e5d 100644 --- a/rpc/rpctest.cc +++ b/rpc/rpctest.cc @@ -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 -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 @@ -52,7 +52,7 @@ srv::handle_fast(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; } @@ -68,7 +68,7 @@ srv service; 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); @@ -80,8 +80,8 @@ testmarshall() { marshall m; request_header rh{1,2,3,4,5}; - m.pack_req_header(rh); - VERIFY(m.size()==RPC_HEADER_SZ); + m.pack_header(rh); + VERIFY(((string)m).size()==RPC_HEADER_SZ); int i = 12345; unsigned long long l = 1223344455L; string s = "hallo...."; @@ -89,14 +89,12 @@ testmarshall() m << l; m << s; - char *b; - size_t sz; - m.take_buf(&b,&sz); - VERIFY(sz == RPC_HEADER_SZ+sizeof(i)+sizeof(l)+s.size()+sizeof(int)); + string b = m; + VERIFY(b.size() == RPC_HEADER_SZ+sizeof(i)+sizeof(l)+s.size()+sizeof(int)); - unmarshall un(b,sz); + unmarshall un(b, true); request_header rh1; - un.unpack_req_header(&rh1); + un.unpack_header(rh1); VERIFY(memcmp(&rh,&rh1,sizeof(rh))==0); int i1; unsigned long long l1; @@ -131,11 +129,11 @@ client1(size_t cl) int arg = (random() % 1000); int rep; - auto start = std::chrono::steady_clock::now(); + auto start = steady_clock::now(); int ret = clients[which_cl]->call(which ? 23 : 24, rep, arg); - auto end = std::chrono::steady_clock::now(); - auto diff = std::chrono::duration_cast(end - start).count(); + auto end = steady_clock::now(); + auto diff = duration_cast(end - start).count(); if (ret != 0) cout << diff << " ms have elapsed!!!" << endl; VERIFY(ret == 0); @@ -168,7 +166,7 @@ client3(void *xx) 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, rpcc::to(300), rep, i); VERIFY(ret == rpc_const::timeout_failure || rep == i+2); } } @@ -189,14 +187,14 @@ simple_tests(rpcc *c) 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, rpcc::to(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; - intret = c->call_timeout(23, rpcc::to(3000), xx, 77); + intret = c->call_timeout(23, rpcc::to(300), xx, 77); VERIFY(intret == 0 && xx == 78); cout << " -- no spurious timeout .. ok" << endl; @@ -204,7 +202,7 @@ simple_tests(rpcc *c) { string arg(1000, 'x'); string rep2; - c->call_timeout(22, rpcc::to(3000), rep2, arg, (string)"x"); + c->call_timeout(22, rpcc::to(300), rep2, arg, (string)"x"); VERIFY(rep2.size() == 1001); cout << " -- no spurious timeout .. ok" << endl; } @@ -219,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); - intret = c1->bind(rpcc::to(3000)); + intret = c1->bind(rpcc::to(300)); time_t t1 = time(0); VERIFY(intret < 0 && (t1 - t0) <= 4); cout << " -- rpc timeout .. ok" << endl; @@ -373,7 +371,7 @@ main(int argc, char *argv[]) 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); @@ -401,7 +399,7 @@ main(int argc, char *argv[]) if (isclient) { // server's address. - dst = "127.0.0.1:" + std::to_string(port); + dst = "127.0.0.1:" + to_string(port); // start the client. bind it to the server. @@ -427,6 +425,6 @@ main(int argc, char *argv[]) } while (1) { - sleep(1); + usleep(100000); } }