-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCPPAsyncServerTest.cpp
More file actions
48 lines (40 loc) · 928 Bytes
/
Copy pathCPPAsyncServerTest.cpp
File metadata and controls
48 lines (40 loc) · 928 Bytes
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
#include "ServerCode.h"
std::mutex m;
std::queue<boost::array<unsigned char, 1>> bufferQueue;
void Execute(boost::asio::io_context* io)
{
io->run();
}
int main()
{
boost::signals2::signal<void()> recvSignal;
recvSignal.connect([&] {
std::lock_guard<std::mutex> lg(m);
boost::array<unsigned char, 1> msg = bufferQueue.front();
std::string data(bufferQueue.front().begin(), bufferQueue.front().end());
std::cout << data;
bufferQueue.pop();
});
int option;
std::cout << "press 1 for server or 2 for client.\n";
std::cin >> option;
try
{
boost::asio::io_context io;
ServerCode server(&recvSignal, io, &m, &bufferQueue);
std::thread t(Execute, &io);
t.detach();
if (option == 1) {
system("pause");
t.~thread();
}
else {
server.StartSend();
t.~thread();
}
}
catch (std::exception& e)
{
std::cerr << e.what() << std::endl;
}
}