-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathmain.cpp
121 lines (102 loc) · 2.33 KB
/
main.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
112
113
114
115
116
117
118
119
120
121
#include <iostream>
#include <string>
#include <tuple>
#include <fstream>
#include <kapok/Kapok.hpp>
#include <boost/timer.hpp>
#include "router.hpp"
#include "test_router.hpp"
#include "server.hpp"
#include "base64.hpp"
#include "client_proxy/client_proxy.hpp"
struct person
{
int age;
std::string name;
META(age, name);
};
int add(int a, int b)
{
return a + b;
}
void hello()
{
std::cout << "hello" << std::endl;
}
void test_one(int d)
{
std::cout << d << std::endl;
}
void foo(std::string b, int a)
{
std::cout << b << std::endl;
}
void fun(const person& ps)
{
std::cout << ps.name << std::endl;
}
int fun1(const person& ps, int a)
{
std::cout << ps.name <<" "<<a<< std::endl;
return a;
}
TEST_CASE(asio_test_server, false)
{
server s(9000, std::thread::hardware_concurrency());
s.register_handler("fun1", &fun1);
s.register_handler("fun", &fun);
s.register_handler("add", &add);
s.register_handler("about", &hello);
s.register_handler("foo", &foo);
s.register_handler("test_one", &test_one);
s.run();
getchar();
}
TEST_CASE(asio_test, false)
{
server s(9000, std::thread::hardware_concurrency());
s.run();
getchar();
}
struct messenger
{
std::string translate(const std::string& orignal)
{
std::string temp = orignal;
for (auto & c : temp) c = toupper(c);
return temp;
}
bool upload(const std::string& filename, const std::string& content)
{
std::ofstream file(filename, ios::binary);
if (!file.is_open())
return false;
auto decode_str = base64_decode(content);
file << decode_str;
file.close();
return true;
}
};
TEST_CASE(rpc_qps, true)
{
messenger m;
server s(9000, std::thread::hardware_concurrency()); //if you fill the last param, the server will remove timeout connections. default never timeout.
s.register_handler("add", &add);;
s.register_handler("translate", &messenger::translate, &m);
s.register_handler("upload", &messenger::upload, &m);
s.run();
//client
//boost::asio::io_service ios;
//client_proxy client(ios);
//client.connect("xxx.xxx...", "9000");
//client.call(...);
getchar();
std::uint64_t last_succeed_count = 0;
while (true)
{
auto curr_succeed_count = (std::uint64_t)g_succeed_count;
std::cout << curr_succeed_count - last_succeed_count << std::endl;
last_succeed_count = curr_succeed_count;
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
}