diff options
Diffstat (limited to 'http.cpp')
-rw-r--r-- | http.cpp | 54 |
1 files changed, 24 insertions, 30 deletions
@@ -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<unsigned short>(std::atoi(config.Sockets()[0].port.data())); - auto const doc_root = std::make_shared<std::string>(config.Sites()[0].paths[0].params.at("target")); - auto const threads = std::max<int>(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<listener>( - ioc, - tcp::endpoint{address, port}, - doc_root)->run(); - - // Run the I/O service on the requested number of threads - std::vector<std::thread> 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<unsigned short>(std::atoi(m_socket.port.data())); + auto const doc_root = std::make_shared<std::string>(m_config.Sites()[0].paths[0].params.at("target")); + + // Create and launch a listening port + std::make_shared<listener>( + m_ioc, + tcp::endpoint{address, port}, + doc_root)->run(); + + return EXIT_SUCCESS; + } } // namespace HTTP |