-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
52 lines (40 loc) · 1.4 KB
/
Copy pathmain.cpp
File metadata and controls
52 lines (40 loc) · 1.4 KB
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
#include <boost/asio/signal_set.hpp>
#include "network/server.hpp"
int main(int argc, char* argv[]) {
std::string filename = "file.log";
asio::ip::port_type port = 1883;
for(int i = 1; i < argc; i += 2) {
if(std::string(argv[i]) == "-p") {
if (i + 1 < argc && argv[i + 1][0] != '-') {
port = std::atoi(argv[i + 1]);
}
else
return -1;
}
if(std::string(argv[i]) == "-f") {
if (i + 1 < argc)
filename = argv[i + 1];
else
return -1;
}
}
std::cout << " __ __ ____ _______ _______ ____ __ __ \n"
<< " | \\/ | / __ \\|__ __||__ __| |___ \\ /_ | /_ | \n"
<< " | \\ / || | | | | | | | __ __ __) | | | | |\n"
<< " | |\\/| || | | | | | | | \\ \\ / /|__ < | | | |\n"
<< " | | | || |__| | | | | | \\ V / ___) |_ | | _ | |\n"
<< " |_| |_| \\___\\_\\ |_| |_| \\_/ |____/(_)|_|(_)|_|\n";
std::cout << '\n' << "Filename: " << filename << " port: " << port << '\n';
asio::io_context io;
tcp::acceptor ac{ io, {tcp::v4(), port} };
asio::signal_set signals(io, SIGINT, SIGTERM);
try {
asio::co_spawn(io, network::server.Listen(std::move(ac), filename), asio::detached);
signals.async_wait([&](auto, auto) {io.stop(); });
io.run();
}
catch (std::exception&) {
Log(filename, info, 0, "Error in the main file");
}
}