forked from dase/CLAIMS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.cpp
More file actions
128 lines (115 loc) · 2.86 KB
/
Client.cpp
File metadata and controls
128 lines (115 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* Client.cpp
*
* Created on: Sep 25, 2014
* Author: wangli
*/
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <fstream>
#include <string>
#include "./startup.h"
#include "Client/ClientResponse.h"
#include "Client/Client.h"
#define GLOG_NO_ABBREVIATED_SEVERITIES
#include "common/log/logging.h"
#include "common/Block/ResultSet.h"
#include "utility/command_line.h"
#include "utility/rdtsc.h"
void readStrigFromTerminal(string& input) {
while (true) {
std::cin.clear();
std::cin.sync();
std::string str;
if (getline(std::cin, str)) {
bool finish = false;
for (unsigned i = 0; i < str.length(); i++) {
if (str[i] == ';') {
input += str.substr(0, i + 1);
finish = true;
break;
}
}
if (finish) break;
input += str + " ";
}
}
}
void submit_command(Client& client, std::string& command) {
ResultSet rs;
std::string message;
switch (client.submit(command, message, rs)) {
case Client::result:
rs.print();
// if(i!=0)
// total_time+=rs.query_time_;
break;
case Client::message:
printf("%s", message.c_str());
break;
case Client::error:
printf("%s", message.c_str());
break;
default:
assert(false);
break;
}
}
void submit_command_repeated(Client& client, std::string& command,
int repeated) {
double total_time = 0;
for (int i = 0; i < repeated; i++) {
ResultSet rs;
std::string message;
switch (client.submit(command, message, rs)) {
case Client::result:
if (i != 0) total_time += rs.query_time_;
break;
case Client::message:
printf("%s", message.c_str());
break;
case Client::error:
printf("%s", message.c_str());
break;
default:
assert(false);
break;
}
}
}
int main(int argc, char** argv) {
/* Client */
if (argc != 3) {
printf(
"argc=%d, Illegal input. \nPlease use client master_ip "
"client_listener_port.\n",
argc);
printf(
"HINT: the master ip and the client_listener_port can be found in the "
"configure file.\n");
return 0;
}
claims::common::Logging claims_logging(argv[0]);
print_welcome();
Client client;
client.connection(argv[1], atoi(argv[2]));
std::cout << std::endl;
init_command_line();
while (1) {
std::string command, message;
get_one_command(command);
command = trimSpecialCharactor(command);
if (command == "exit;" || command == "shutdown;") {
break;
} else if (command.empty()) {
continue;
}
submit_command(client, command);
/*
* the following command execute the query for a given time and p
* rint the averaged query response time.*/
// submit_command_repeated(client,command,50);
}
client.shutdown();
}