-
Notifications
You must be signed in to change notification settings - Fork 3
/
blink.cpp
56 lines (39 loc) · 1.08 KB
/
blink.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
#include "reactor.hpp"
#include <vector>
#include <thread>
#include <algorithm>
#include <signal.h>
#include "debug.hpp"
#include "acceptor.hpp"
const int SESSION_THREAD_COUNT = 2;
int main()
{
DEBUG("[STARTUP]");
signal(SIGPIPE, SIG_IGN);
ReactorPtr acceptor_reactor(new Reactor());
ReactorPtr session_reactor(new Reactor());
AcceptorPtr acceptor = Acceptor::create(acceptor_reactor, session_reactor);
acceptor->open();
std::thread acceptor_thread([&]()
{
DEBUG("[acceptor_event_loop] STARTUP");
acceptor_reactor->handle_events();
DEBUG("[acceptor_event_loop] SHUTDOWN");
});
std::vector<std::thread> workers;
for (int i = 0; i < SESSION_THREAD_COUNT; i++) {
workers.push_back(std::thread([&]()
{
DEBUG("[session_event_loop] STARTUP");
session_reactor->handle_events();
DEBUG("[session_event_loop] SHUTDOWN");
}));
}
acceptor_thread.join();
std::for_each(workers.begin(), workers.end(), [](std::thread &t)
{
t.join();
});
DEBUG("[SHUTDOWN]");
return 0;
}