-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cxx
40 lines (39 loc) · 1.09 KB
/
main.cxx
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
#include "src/database/database.hxx"
#include "src/server/server.hxx"
#include <boost/bind/bind.hpp>
#include <exception>
#include <iostream>
#include <sodium.h>
#include <stdexcept>
int
main ()
{
#ifdef DEBUG
std::cout << "DEBUG" << std::endl;
#else
std::cout << "NO DEBUG" << std::endl;
#endif
try
{
if (sodium_init () < 0)
{
std::cout << "sodium_init => 0" << std::endl;
std::terminate ();
/* panic! the library couldn't be initialized, it is not safe to use */
}
database::createEmptyDatabase ();
database::createTables ();
boost::asio::io_context io_context (1);
boost::asio::signal_set signals (io_context, SIGINT, SIGTERM);
signals.async_wait ([&] (auto, auto) { io_context.stop (); });
boost::asio::thread_pool pool{ 2 };
auto server = Server{ io_context, pool };
co_spawn (io_context, boost::bind (&Server::listener, boost::ref (server)), boost::asio::detached);
io_context.run ();
}
catch (std::exception &e)
{
std::printf ("Exception: %s\n", e.what ());
}
return 0;
}