-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cc
executable file
·55 lines (48 loc) · 1.51 KB
/
main.cc
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
/// @brief - A minimalistic bsg server implementation
#include "Server.hh"
#include <core_utils/CoreException.hh>
#include <core_utils/log/Locator.hh>
#include <core_utils/log/PrefixedLogger.hh>
#include <core_utils/log/StdLogger.hh>
#include <functional>
namespace {
// https://stackoverflow.com/questions/11468414/using-auto-and-lambda-to-handle-signal
std::function<void(int)> sigIntProcessing;
void sigIntInterceptor(const int signal)
{
sigIntProcessing(signal);
}
} // namespace
int main(int /*argc*/, char ** /*argv*/)
{
// Create the logger.
utils::log::StdLogger raw;
raw.setLevel(utils::log::Severity::DEBUG);
utils::log::PrefixedLogger logger("server", "main");
utils::log::Locator::provide(&raw);
try
{
bsgo::Server server;
sigIntProcessing = [&server](const int /*signal*/) { server.requestStop(); };
// https://en.cppreference.com/w/cpp/utility/program/signal
std::signal(SIGINT, sigIntInterceptor);
constexpr auto DEFAULT_SERVER_PORT = 60000;
server.run(DEFAULT_SERVER_PORT);
}
catch (const utils::CoreException &e)
{
logger.error("Caught internal exception while setting up application", e.what());
return EXIT_FAILURE;
}
catch (const std::exception &e)
{
logger.error("Caught internal exception while setting up application", e.what());
return EXIT_FAILURE;
}
catch (...)
{
logger.error("Unexpected error while setting up application");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}