From 1fcaed7a34cce8e55bb071d503bb583f715e7d37 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 4 Apr 2020 19:24:16 +0200 Subject: Serve configured sockets --- server.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) (limited to 'server.cpp') diff --git a/server.cpp b/server.cpp index 2ad9bcd..bbe7223 100644 --- a/server.cpp +++ b/server.cpp @@ -1,10 +1,62 @@ +#include +#include +#include +#include +#include +#include +#include + +#include +#include + #include "server.h" #include "http.h" #include "https.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) { - //return HTTP::server(config); - return HTTPS::server(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(); + } + + // 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; } + -- cgit v1.2.3