]>
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 <boost/noncopyable.hpp> | |
17 | #include "connection.hpp" | |
18 | #include "connection_manager.hpp" | |
19 | #include "request_handler.hpp" | |
20 | ||
21 | namespace http { | |
22 | namespace server { | |
23 | ||
24 | /// The top-level class of the HTTP server. | |
25 | class server | |
26 | : private boost::noncopyable | |
27 | { | |
28 | public: | |
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); | |
33 | ||
b32b8144 | 34 | /// Run the server's io_context loop. |
7c673cae FG |
35 | void run(); |
36 | ||
37 | private: | |
38 | /// Initiate an asynchronous accept operation. | |
39 | void start_accept(); | |
40 | ||
41 | /// Handle completion of an asynchronous accept operation. | |
42 | void handle_accept(const boost::system::error_code& e); | |
43 | ||
44 | /// Handle a request to stop the server. | |
45 | void handle_stop(); | |
46 | ||
b32b8144 FG |
47 | /// The io_context used to perform asynchronous operations. |
48 | boost::asio::io_context io_context_; | |
7c673cae FG |
49 | |
50 | /// The signal_set is used to register for process termination notifications. | |
51 | boost::asio::signal_set signals_; | |
52 | ||
53 | /// Acceptor used to listen for incoming connections. | |
54 | boost::asio::ip::tcp::acceptor acceptor_; | |
55 | ||
56 | /// The connection manager which owns all live connections. | |
57 | connection_manager connection_manager_; | |
58 | ||
59 | /// The next connection to be accepted. | |
60 | connection_ptr new_connection_; | |
61 | ||
62 | /// The handler for all incoming requests. | |
63 | request_handler request_handler_; | |
64 | }; | |
65 | ||
66 | } // namespace server | |
67 | } // namespace http | |
68 | ||
69 | #endif // HTTP_SERVER_HPP |