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
int
srv::handle_slow(int &r, const int a)
{
- usleep(random() % 5000);
+ usleep(random() % 500);
r = a + 2;
return 0;
}
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);
{
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....";
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;
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<std::chrono::milliseconds>(end - start).count();
+ auto end = steady_clock::now();
+ auto diff = duration_cast<milliseconds>(end - start).count();
if (ret != 0)
cout << diff << " ms have elapsed!!!" << endl;
VERIFY(ret == 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, rpcc::to(300), rep, i);
VERIFY(ret == rpc_const::timeout_failure || rep == i+2);
}
}
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;
{
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;
}
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;
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);
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.
}
while (1) {
- sleep(1);
+ usleep(100000);
}
}