-
Notifications
You must be signed in to change notification settings - Fork 51
/
test.cpp
111 lines (91 loc) · 2.18 KB
/
test.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
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
#include <iostream>
#include <atomic>
#include <random>
#include <future>
#include <pool/thread.hpp>
#include "./tcp/tcp_server.h"
#include "./tcp/protobuf/protobuf_server.h"
BrinK::tcp::server server;
std::atomic_bool sig_exit;
#include <pool/shared.hpp>
void random_test_broadcast()
{
static int send_count=0;
while (!sig_exit)
{
server.broadcast("Broadcast!!!");
BrinK::utils::sleep(BrinK::utils::random(100,200));
}
}
void random_test_start_stop()
{
while (!sig_exit)
{
server.start(80);
BrinK::utils::sleep(BrinK::utils::random(100, 200));
server.stop();
}
}
int main(int, char**)
{
unsigned int port=80;
server.start(port);
std::cout << "Server started port : " << port << std::endl;
do
{
std::string cmd;
std::getline(std::cin, cmd);
if (cmd == "q")
{
std::cout << "Stop server" << std::endl;
std::async([]
{
server.stop();
});
}
else if (cmd == "s")
{
std::cout << "Start server" << std::endl;
std::async([port]
{
server.start(port);
});
}
else if (cmd == "t")
{
std::cout << "Test thread start/stop" << std::endl;
sig_exit = false;
std::async([]{random_test_start_stop(); });
}
else if (cmd.substr(0, 1) == "w")
{
std::cout << "Start broadcast thread" << std::endl;
sig_exit = false;
std::async([]
{
random_test_broadcast();
});
}
else if (cmd == "b")
{
std::cout << "Broadcast msg" << std::endl;
std::async([]
{
server.broadcast("A test");
});
}
else if (cmd == "p")
{
std::async([]
{
});
}
else if (cmd == "qt")
{
std::cout << "Stop threads" << std::endl;
sig_exit = true;
}
} while (true);
system("pause");
return 0;
}