#include #ifdef WIN32 #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include "./session/WebsocketSession.h" #include "./listener/Listener.h" #include "./db/mysql_connector.h" #include "entities/user.h" #include "log/Log.h" namespace beast = boost::beast; namespace http = beast::http; namespace websocket = beast::websocket; namespace net = boost::asio; using tcp = boost::asio::ip::tcp; using namespace uad; using namespace std; using namespace std::string_literals; namespace logging = boost::log; int main(int argc, char* argv[]) { if (argc != 6) { std::cerr << "Usage: advanced-server
\n" << "Example:\n" << " advanced-server 0.0.0.0 8080 . 1\n"; return EXIT_FAILURE; } auto const address = net::ip::make_address(argv[1]); auto const port = static_cast(std::atoi(argv[2])); auto const doc_root = std::make_shared(argv[3]); auto const threads = std::max(1, std::atoi(argv[4])); string mysql_credentials = argv[5]; InitLogs(); uad::SetMySqlSession(new mysqlx::Session(mysql_credentials)); net::io_context ioc{threads}; std::make_shared(ioc, tcp::endpoint{address, port}, doc_root)->Run(); net::signal_set signals(ioc, SIGINT, SIGTERM); signals.async_wait([&](beast::error_code const&, int) { ioc.stop(); }); BOOST_LOG_TRIVIAL(info) << "Приложение запущено"; std::vector v; v.reserve(threads - 1); for (auto i = threads - 1; i > 0; --i) v.emplace_back([&ioc] { ioc.run(); }); ioc.run(); for (auto& t : v) t.join(); return EXIT_SUCCESS; }