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 --- https.cpp | 57 +++++++++++++++++++++++---------------------------------- 1 file changed, 23 insertions(+), 34 deletions(-) (limited to 'https.cpp') diff --git a/https.cpp b/https.cpp index 0c3b97b..b4e77f9 100644 --- a/https.cpp +++ b/https.cpp @@ -515,42 +515,31 @@ private: namespace HTTPS { -int server(Config& config) +Server::Server(Config& config, boost::asio::io_context& ioc, const Socket& socket): ::Server(config, ioc), m_socket(socket) { - // TODO: Config - auto const address = net::ip::make_address(config.Sockets()[0].address); - auto const port = static_cast(std::atoi(config.Sockets()[0].port.data())); - auto const doc_root = std::make_shared(config.Sites()[0].paths[0].params.at("target")); - auto const threads = std::max(1, config.Threads()); - - // The io_context is required for all I/O - net::io_context ioc{threads}; - - // The SSL context is required, and holds certificates - ssl::context ctx{ssl::context::tlsv13}; - - // This holds the self-signed certificate used by the server - load_server_certificate(ctx, config.Sockets()[0].cert_path, config.Sockets()[0].key_path); // TODO: config - - // Create and launch a listening port - std::make_shared( - ioc, - ctx, - tcp::endpoint{address, port}, - doc_root)->run(); - - // 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(); + // This holds the self-signed certificate used by the server + load_server_certificate(m_ctx, m_socket.cert_path, m_socket.key_path); +} + +Server::~Server() +{ +} - return EXIT_SUCCESS; +int Server::start() +{ + // TODO: Config + auto const address = net::ip::make_address(m_socket.address); + auto const port = static_cast(std::atoi(m_socket.port.data())); + auto const doc_root = std::make_shared(m_config.Sites()[0].paths[0].params.at("target")); + + // Create and launch a listening port + std::make_shared( + m_ioc, + m_ctx, + tcp::endpoint{address, port}, + doc_root)->run(); + + return EXIT_SUCCESS; } } // namespace HTTPS -- cgit v1.2.3