#define NUM_CL 2
+char tprintf_thread_prefix = 'r';
+
rpcs *server; // server rpc object
rpcc *clients[NUM_CL]; // client rpc object
struct sockaddr_in dst; //server's ip address
int handle_22(std::string & r, const std::string a, const std::string b);
int handle_fast(int &r, const int a);
int handle_slow(int &r, const int a);
- int handle_bigrep(std::string &r, const int a);
+ int handle_bigrep(std::string &r, const size_t a);
};
// a handler. a and b are arguments, r is the result.
}
int
-srv::handle_bigrep(std::string &r, const int len)
+srv::handle_bigrep(std::string &r, const size_t len)
{
- r = std::string(len, 'x');
+ r = std::string((size_t)len, 'x');
return 0;
}
void startserver()
{
- server = new rpcs(port);
+ server = new rpcs((unsigned int)port);
server->reg(22, &srv::handle_22, &service);
server->reg(23, &srv::handle_fast, &service);
server->reg(24, &srv::handle_slow, &service);
m << s;
char *b;
- int sz;
+ size_t sz;
m.take_buf(&b,&sz);
- VERIFY(sz == (int)(RPC_HEADER_SZ+sizeof(i)+sizeof(l)+s.size()+sizeof(int)));
+ VERIFY(sz == RPC_HEADER_SZ+sizeof(i)+sizeof(l)+s.size()+sizeof(int));
unmarshall un(b,sz);
request_header rh1;
}
void
-client1(int cl)
+client1(size_t cl)
{
// test concurrency.
- int which_cl = ((unsigned long) cl ) % NUM_CL;
+ size_t which_cl = cl % NUM_CL;
for(int i = 0; i < 100; i++){
int arg = (random() % 2000);
int ret = clients[which_cl]->call(which ? 23 : 24, rep, arg);
auto end = std::chrono::steady_clock::now();
- int diff = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
+ auto diff = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
if (ret != 0)
- printf("%d ms have elapsed!!!\n", diff);
+ printf("%d ms have elapsed!!!\n", (int)diff);
VERIFY(ret == 0);
VERIFY(rep == (which ? arg+1 : arg+2));
}
}
void
-client2(int cl)
+client2(size_t cl)
{
- int which_cl = ((unsigned long) cl ) % NUM_CL;
+ size_t which_cl = cl % NUM_CL;
time_t t1;
time(&t1);
// specify a timeout value to an RPC that should succeed (tcp)
{
std::string arg(1000, 'x');
- std::string rep;
- c->call_timeout(22, rpcc::to(3000), rep, arg, (std::string)"x");
- VERIFY(rep.size() == 1001);
+ std::string rep2;
+ c->call_timeout(22, rpcc::to(3000), rep2, arg, (std::string)"x");
+ VERIFY(rep2.size() == 1001);
printf(" -- no spurious timeout .. ok\n");
}
}
void
-concurrent_test(int nt)
+concurrent_test(size_t nt)
{
// create threads that make lots of calls in parallel,
// to test thread synchronization for concurrent calls
// and dispatches.
- printf("start concurrent_test (%d threads) ...", nt);
+ printf("start concurrent_test (%lu threads) ...", nt);
std::vector<std::thread> th(nt);
- for(int i = 0; i < nt; i++){
+
+ for(size_t i = 0; i < nt; i++)
th[i] = std::thread(client1, i);
- }
- for(int i = 0; i < nt; i++){
+ for(size_t i = 0; i < nt; i++)
th[i].join();
- }
+
printf(" OK\n");
}
VERIFY(clients[i]->bind()==0);
}
- int nt = 1;
+ size_t nt = 1;
+
std::vector<std::thread> th(nt);
- for(int i = 0; i < nt; i++){
+
+ for(size_t i = 0; i < nt; i++)
th[i] = std::thread(client2, i);
- }
- for(int i = 0; i < nt; i++){
+
+ for(size_t i = 0; i < nt; i++)
th[i].join();
- }
+
printf(".. OK\n");
VERIFY(setenv("RPC_LOSSY", "0", 1) == 0);
}
printf(" -- delete existing rpc client, create replacement rpc client .. ok\n");
- int nt = 10;
- printf(" -- concurrent test on new rpc client w/ %d threads ..", nt);
+ size_t nt = 10;
+ printf(" -- concurrent test on new rpc client w/ %lu threads ..", nt);
std::vector<std::thread> th(nt);
- for(int i = 0; i < nt; i++){
+
+ for(size_t i = 0; i < nt; i++)
th[i] = std::thread(client3, client);
- }
- for(int i = 0; i < nt; i++){
+ for(size_t i = 0; i < nt; i++)
th[i].join();
- }
+
printf("ok\n");
delete server;
VERIFY (client->bind() >= 0);
printf(" -- delete existing rpc client and server, create replacements.. ok\n");
- printf(" -- concurrent test on new client and server w/ %d threads ..", nt);
- for(int i = 0; i < nt; i++){
+ printf(" -- concurrent test on new client and server w/ %lu threads ..", nt);
+
+ for(size_t i = 0; i < nt; i++)
th[i] = std::thread(client3, client);
- }
- for(int i = 0; i < nt; i++){
+ for(size_t i = 0; i < nt; i++)
th[i].join();
- }
+
printf("ok\n");
printf("failure_test OK\n");
bool isclient = false;
bool isserver = false;
- srandom(getpid());
+ srandom((uint32_t)getpid());
port = 20000 + (getpid() % 10000);
- char ch = 0;
+ int ch = 0;
while ((ch = getopt(argc, argv, "csd:p:l"))!=-1) {
switch (ch) {
case 'c':
break;
case 'l':
VERIFY(setenv("RPC_LOSSY", "5", 1) == 0);
+ break;
default:
break;
}