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 --- http.cpp | 54 ++++++++++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 30 deletions(-) (limited to 'http.cpp') diff --git a/http.cpp b/http.cpp index 82e1a39..aea4e07 100644 --- a/http.cpp +++ b/http.cpp @@ -153,6 +153,7 @@ handle_request( // Build the path to the requested file std::string path = path_cat(doc_root, req.target()); + std::cout << "DEBUG: " << req["host"] << std::endl; if(req.target().back() == '/') path.append("index.html"); @@ -446,35 +447,28 @@ private: namespace HTTP { -int server(Config& config) -{ - // 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}; - - // Create and launch a listening port - std::make_shared( - ioc, - 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(); - - return EXIT_SUCCESS; -} + Server::Server(Config& config, boost::asio::io_context& ioc, const Socket& socket): ::Server(config, ioc), m_socket(socket) + { + } + + Server::~Server() + { + } + + 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, + tcp::endpoint{address, port}, + doc_root)->run(); + + return EXIT_SUCCESS; + } } // namespace HTTP -- cgit v1.2.3