diff options
author | Roland Reichwein <mail@reichwein.it> | 2020-04-04 19:24:16 +0200 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2020-04-04 19:24:16 +0200 |
commit | 1fcaed7a34cce8e55bb071d503bb583f715e7d37 (patch) | |
tree | 9c6bcaa267a66b902f308ee253a79da874780e55 /http.cpp | |
parent | 938fbe7a2f2f10a3abb530a9463e57fc20f40038 (diff) |
Serve configured sockets
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 |