projects
/
invirt/third/libt4.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
All sleep calls via std::this_thread
[invirt/third/libt4.git]
/
rpc
/
rpctest.cc
diff --git
a/rpc/rpctest.cc
b/rpc/rpctest.cc
index
fb170e7
..
0435ab1
100644
(file)
--- a/
rpc/rpctest.cc
+++ b/
rpc/rpctest.cc
@@
-7,14
+7,13
@@
#include <getopt.h>
#include <unistd.h>
#include <string.h>
#include <getopt.h>
#include <unistd.h>
#include <string.h>
+#include "threaded_log.h"
#define NUM_CL 2
#define NUM_CL 2
-char log_thread_prefix = 'r';
-
static rpcs *server; // server rpc object
static rpcc *clients[NUM_CL]; // client rpc object
static rpcs *server; // server rpc object
static rpcc *clients[NUM_CL]; // client rpc object
-static string dst; //server's ip address
+static string * dst; //server's ip address
static in_port_t port;
using std::cout;
static in_port_t port;
using std::cout;
@@
-60,7
+59,8
@@
int 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() % 500);
+ int us = std::uniform_int_distribution<>(0,500)(global->random_generator);
+ std::this_thread::sleep_for(microseconds(us));
r = a + 2;
return 0;
}
r = a + 2;
return 0;
}
@@
-123,7
+123,7
@@
static void client1(size_t cl) {
size_t which_cl = cl % NUM_CL;
for(int i = 0; i < 100; i++){
size_t which_cl = cl % NUM_CL;
for(int i = 0; i < 100; i++){
- unsigned long arg = (random() % 2000);
+ auto arg = std::uniform_int_distribution<unsigned long>(0,2000)(global->random_generator);
string rep;
int ret = clients[which_cl]->call(srv_protocol::bigrep, rep, arg);
VERIFY(ret == 0);
string rep;
int ret = clients[which_cl]->call(srv_protocol::bigrep, rep, arg);
VERIFY(ret == 0);
@@
-135,8
+135,8
@@
static void client1(size_t cl) {
// test rpc replies coming back not in the order of
// the original calls -- i.e. does xid reply dispatch work.
for(int i = 0; i < 100; i++){
// test rpc replies coming back not in the order of
// the original calls -- i.e. does xid reply dispatch work.
for(int i = 0; i < 100; i++){
- int which = (random() % 2);
- int arg = (random() % 1000);
+ bool which = std::bernoulli_distribution()(global->random_generator);
+ int arg = std::uniform_int_distribution<>(0,1000)(global->random_generator);
int rep = -1;
auto start = steady_clock::now();
int rep = -1;
auto start = steady_clock::now();
@@
-158,7
+158,7
@@
static void client2(size_t cl) {
time(&t1);
while(time(0) - t1 < 10){
time(&t1);
while(time(0) - t1 < 10){
- unsigned long arg = (random() % 2000);
+ auto arg = std::uniform_int_distribution<unsigned long>(0,2000)(global->random_generator);
string rep;
int ret = clients[which_cl]->call(srv_protocol::bigrep, rep, arg);
if ((unsigned long)rep.size()!=arg)
string rep;
int ret = clients[which_cl]->call(srv_protocol::bigrep, rep, arg);
if ((unsigned long)rep.size()!=arg)
@@
-256,7
+256,7
@@
static void lossy_test() {
for (int i = 0; i < NUM_CL; i++) {
delete clients[i];
for (int i = 0; i < NUM_CL; i++) {
delete clients[i];
- clients[i] = new rpcc(dst);
+ clients[i] = new rpcc(*dst);
VERIFY(clients[i]->bind()==0);
}
VERIFY(clients[i]->bind()==0);
}
@@
-282,7
+282,7
@@
static void failure_test() {
delete server;
delete server;
- client1 = new rpcc(dst);
+ client1 = new rpcc(*dst);
VERIFY (client1->bind(milliseconds(3000)) < 0);
cout << " -- create new client and try to bind to failed server .. failed ok" << endl;
VERIFY (client1->bind(milliseconds(3000)) < 0);
cout << " -- create new client and try to bind to failed server .. failed ok" << endl;
@@
-297,7
+297,7
@@
static void failure_test() {
delete client;
delete client;
- clients[0] = client = new rpcc(dst);
+ clients[0] = client = new rpcc(*dst);
VERIFY (client->bind() >= 0);
VERIFY (client->bind() < 0);
VERIFY (client->bind() >= 0);
VERIFY (client->bind() < 0);
@@
-325,7
+325,7
@@
static void failure_test() {
delete client;
startserver();
delete client;
startserver();
- clients[0] = client = new rpcc(dst);
+ clients[0] = client = new rpcc(*dst);
VERIFY (client->bind() >= 0);
cout << " -- delete existing rpc client and server, create replacements.. ok" << endl;
VERIFY (client->bind() >= 0);
cout << " -- delete existing rpc client and server, create replacements.. ok" << endl;
@@
-343,6
+343,7
@@
static void failure_test() {
}
int main(int argc, char *argv[]) {
}
int main(int argc, char *argv[]) {
+ global = new t4_state('r');
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
@@
-351,7
+352,6
@@
int main(int argc, char *argv[]) {
bool isclient = false;
bool isserver = false;
bool isclient = false;
bool isserver = false;
- srandom((uint32_t)getpid());
port = 20000 + (getpid() % 10000);
int ch = 0;
port = 20000 + (getpid() % 10000);
int ch = 0;
@@
-382,7
+382,7
@@
int main(int argc, char *argv[]) {
}
if (debug_level > 0) {
}
if (debug_level > 0) {
- DEBUG_LEVEL = debug_level;
+ global->DEBUG_LEVEL = debug_level;
IF_LEVEL(1) LOG_NONMEMBER << "DEBUG LEVEL: " << debug_level;
}
IF_LEVEL(1) LOG_NONMEMBER << "DEBUG LEVEL: " << debug_level;
}
@@
-395,7
+395,7
@@
int main(int argc, char *argv[]) {
if (isclient) {
// server's address.
if (isclient) {
// server's address.
- dst = "127.0.0.1:" + std::to_string(port);
+ dst = new string("127.0.0.1:" + std::to_string(port));
// start the client. bind it to the server.
// start the client. bind it to the server.
@@
-404,7
+404,7
@@
int main(int argc, char *argv[]) {
// be only one rpcc per process. you probably need one
// rpcc per server.
for (int i = 0; i < NUM_CL; i++) {
// be only one rpcc per process. you probably need one
// rpcc per server.
for (int i = 0; i < NUM_CL; i++) {
- clients[i] = new rpcc(dst);
+ clients[i] = new rpcc(*dst);
VERIFY (clients[i]->bind() == 0);
}
VERIFY (clients[i]->bind() == 0);
}
@@
-421,5
+421,5
@@
int main(int argc, char *argv[]) {
}
while (1)
}
while (1)
- usleep(100000);
+ std::this_thread::sleep_for(milliseconds(100));
}
}