]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // |
2 | // server.hpp | |
3 | // ~~~~~~~~~~ | |
4 | // | |
b32b8144 | 5 | // Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com) |
7c673cae FG |
6 | // |
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) | |
9 | // | |
10 | ||
11 | #ifndef HTTP_SERVER_HPP | |
12 | #define HTTP_SERVER_HPP | |
13 | ||
14 | #include <boost/asio.hpp> | |
15 | #include <string> | |
16 | #include "connection.hpp" | |
17 | #include "connection_manager.hpp" | |
18 | #include "request_handler.hpp" | |
19 | ||
20 | namespace http { | |
21 | namespace server { | |
22 | ||
23 | /// The top-level class of the HTTP server. | |
24 | class server | |
25 | { | |
26 | public: | |
27 | server(const server&) = delete; | |
28 | server& operator=(const server&) = delete; | |
29 | ||
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); | |
34 | ||
b32b8144 | 35 | /// Run the server's io_context loop. |
7c673cae FG |
36 | void run(); |
37 | ||
38 | private: | |
39 | /// Perform an asynchronous accept operation. | |
40 | void do_accept(); | |
41 | ||
42 | /// Wait for a request to stop the server. | |
43 | void do_await_stop(); | |
44 | ||
b32b8144 FG |
45 | /// The io_context used to perform asynchronous operations. |
46 | boost::asio::io_context io_context_; | |
7c673cae FG |
47 | |
48 | /// The signal_set is used to register for process termination notifications. | |
49 | boost::asio::signal_set signals_; | |
50 | ||
51 | /// Acceptor used to listen for incoming connections. | |
52 | boost::asio::ip::tcp::acceptor acceptor_; | |
53 | ||
54 | /// The connection manager which owns all live connections. | |
55 | connection_manager connection_manager_; | |
56 | ||
7c673cae FG |
57 | /// The handler for all incoming requests. |
58 | request_handler request_handler_; | |
59 | }; | |
60 | ||
61 | } // namespace server | |
62 | } // namespace http | |
63 | ||
64 | #endif // HTTP_SERVER_HPP |