5 // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef HTTP_SERVER3_SERVER_HPP
12 #define HTTP_SERVER3_SERVER_HPP
14 #include <boost/asio.hpp>
17 #include <boost/noncopyable.hpp>
18 #include <boost/shared_ptr.hpp>
19 #include "connection.hpp"
20 #include "request_handler.hpp"
25 /// The top-level class of the HTTP server.
27 : private boost::noncopyable
30 /// Construct the server to listen on the specified TCP address and port, and
31 /// serve up files from the given directory.
32 explicit server(const std::string& address, const std::string& port,
33 const std::string& doc_root, std::size_t thread_pool_size);
35 /// Run the server's io_context loop.
39 /// Initiate an asynchronous accept operation.
42 /// Handle completion of an asynchronous accept operation.
43 void handle_accept(const boost::system::error_code& e);
45 /// Handle a request to stop the server.
48 /// The number of threads that will call io_context::run().
49 std::size_t thread_pool_size_;
51 /// The io_context used to perform asynchronous operations.
52 boost::asio::io_context io_context_;
54 /// The signal_set is used to register for process termination notifications.
55 boost::asio::signal_set signals_;
57 /// Acceptor used to listen for incoming connections.
58 boost::asio::ip::tcp::acceptor acceptor_;
60 /// The next connection to be accepted.
61 connection_ptr new_connection_;
63 /// The handler for all incoming requests.
64 request_handler request_handler_;
67 } // namespace server3
70 #endif // HTTP_SERVER3_SERVER_HPP