-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClientMain.cpp
59 lines (49 loc) · 1.32 KB
/
ClientMain.cpp
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
#include <array>
#include <iostream>
#include <iomanip>
#include <thread>
#include <vector>
#include "ClientSocket.h"
#include "ClientThread.h"
#include "ClientTimer.h"
int main(int argc, char *argv[]) {
std::string ip;
int port;
int num_customers;
int num_orders;
int request_type;
ClientTimer timer;
std::vector<std::shared_ptr<ClientThreadClass>> client_vector;
std::vector<std::thread> thread_vector;
if (argc < 6) {
std::cout << "not enough arguments" << std::endl;
std::cout << argv[0] << " [ip] [port #] [# customers] ";
std::cout << "[# orders] [request type 1, 2 or 3]" << std::endl;
return 0;
}
ip = argv[1];
port = atoi(argv[2]);
num_customers = atoi(argv[3]);
num_orders = atoi(argv[4]);
request_type = atoi(argv[5]);
if(request_type == 3) {
num_customers = 1;
}
timer.Start();
for (int i = 0; i < num_customers; i++) {
auto client_cls = std::shared_ptr<ClientThreadClass>(new ClientThreadClass());
std::thread client_thread(&ClientThreadClass::ThreadBody, client_cls,
ip, port, i, num_orders, request_type);
client_vector.push_back(std::move(client_cls));
thread_vector.push_back(std::move(client_thread));
}
for (auto& th : thread_vector) {
th.join();
}
timer.End();
for (auto& cls : client_vector) {
timer.Merge(cls->GetTimer());
}
timer.PrintStats();
return 1;
}