#include #include #include "communication/bolt/v1/server/server.hpp" #include "communication/bolt/v1/server/worker.hpp" #include "io/network/socket.hpp" #include "logging/default.hpp" #include "logging/streams/stdout.hpp" #include "utils/terminate_handler.hpp" static bolt::Server* serverptr; Logger logger; void sigint_handler(int s) { auto signal = s == SIGINT ? "SIGINT" : "SIGABRT"; logger.info("Recieved signal {}", signal); logger.info("Shutting down..."); std::exit(EXIT_SUCCESS); } static constexpr const char* interface = "0.0.0.0"; static constexpr const char* port = "7687"; int main(void) { // TODO figure out what is the relationship between this and signals // that are configured below std::set_terminate(&terminate_handler); logging::init_sync(); logging::log->pipe(std::make_unique()); logger = logging::log->logger("Main"); signal(SIGINT, sigint_handler); signal(SIGABRT, sigint_handler); io::Socket socket; try { socket = io::Socket::bind(interface, port); } catch(io::NetworkError e) { logger.error("Cannot bind to socket on {} at {}", interface, port); logger.error("{}", e.what()); std::exit(EXIT_FAILURE); } socket.set_non_blocking(); socket.listen(1024); logger.info("Listening on {} at {}", interface, port); bolt::Server server(std::move(socket)); serverptr = &server; constexpr size_t N = 1; logger.info("Starting {} workers", N); server.start(N); logger.info("Shutting down..."); return EXIT_SUCCESS; }