5 // Copyright (c) 2003-2017 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_SERVER_HPP
12 #define HTTP_SERVER_HPP
14 #include <boost/asio.hpp>
16 #include <boost/noncopyable.hpp>
17 #include "connection.hpp"
18 #include "connection_manager.hpp"
19 #include "request_handler.hpp"
24 /// The top-level class of the HTTP server.
26 : private boost::noncopyable
29 /// Construct the server to listen on the specified TCP address and port, and
30 /// serve up files from the given directory.
31 explicit server(const std::string& address, const std::string& port,
32 const std::string& doc_root);
34 /// Run the server's io_context loop.
38 /// Initiate an asynchronous accept operation.
41 /// Handle completion of an asynchronous accept operation.
42 void handle_accept(const boost::system::error_code& e);
44 /// Handle a request to stop the server.
47 /// The io_context used to perform asynchronous operations.
48 boost::asio::io_context io_context_;
50 /// The signal_set is used to register for process termination notifications.
51 boost::asio::signal_set signals_;
53 /// Acceptor used to listen for incoming connections.
54 boost::asio::ip::tcp::acceptor acceptor_;
56 /// The connection manager which owns all live connections.
57 connection_manager connection_manager_;
59 /// The next connection to be accepted.
60 connection_ptr new_connection_;
62 /// The handler for all incoming requests.
63 request_handler request_handler_;
69 #endif // HTTP_SERVER_HPP