#include #include #include #include #include #include #include #include #include #include "server.h" #include "http.h" #include "https.h" #include "privileges.h" namespace beast = boost::beast; // from namespace http = beast::http; // from namespace net = boost::asio; // from namespace ssl = boost::asio::ssl; // from using tcp = boost::asio::ip::tcp; // from Server::Server(Config& config, boost::asio::io_context& ioc): m_config(config), m_ioc(ioc) { } Server::~Server() { } int server(Config& config) { auto const threads = std::max(1, config.Threads()); boost::asio::io_context ioc{threads}; std::vector> servers; const auto& sockets {config.Sockets()}; for (const auto& socket: sockets) { if (socket.protocol == SocketProtocol::HTTP) { servers.push_back(std::make_shared(config, ioc, socket)); } else { servers.push_back(std::make_shared(config, ioc, socket)); } servers.back()->start(); } // set UID, GID drop_privileges(config); // Run the I/O service on the requested number of threads std::vector v; v.reserve(threads - 1); for(auto i = threads - 1; i > 0; --i) v.emplace_back( [&ioc] { ioc.run(); }); ioc.run(); return EXIT_SUCCESS; }