-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathecho_mgr.cpp
63 lines (53 loc) · 1.38 KB
/
echo_mgr.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
#include "echo_mgr.h"
#include <knet/kutils.h>
echo_mgr mgr;
echo_mgr::~echo_mgr()
{
disconnect_all = true;
if (_t) {
_t->join();
delete _t;
}
}
void echo_mgr::update(int64_t delta_ms)
{
_total_ms += delta_ms;
if (_total_ms < 1000) {
return;
}
const auto total_send_mb = total_send.load() / 1024 / 1024;
total_send = 0;
const auto total_recv_num = total_recv.load();
total_recv = 0;
const auto total_delta_s = _total_ms / 1000;
_total_ms %= 1000;
const auto send_mb = total_send_mb / total_delta_s;
const auto recv_num = total_recv_num / total_delta_s;
std::cout << "instance: " << inst_num
<< ", connection: " << conn_num
<< ", send: " << send_mb << " MB/S"
<< ", recv: " << recv_num << " Pkg/S\n";
std::cout.flush();
}
void echo_mgr::check_console_input()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
if (_t) {
return;
}
_t = new std::thread([](echo_mgr* m) {
std::string s;
while (!m->disconnect_all) {
std::cin >> s;
if (s == "exit") {
m->disconnect_all = true;
break;
} else if (s == "log") {
m->can_log = !m->can_log;
}
}
},
this);
std::cout << "enter \"exit\" to exit program" << std::endl;
}