]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // |
2 | // server.hpp | |
3 | // ~~~~~~~~~~ | |
4 | // | |
92f5a8d4 | 5 | // Copyright (c) 2003-2019 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_SERVER2_SERVER_HPP | |
12 | #define HTTP_SERVER2_SERVER_HPP | |
13 | ||
14 | #include <boost/asio.hpp> | |
15 | #include <string> | |
16 | #include <vector> | |
17 | #include <boost/noncopyable.hpp> | |
18 | #include <boost/shared_ptr.hpp> | |
19 | #include "connection.hpp" | |
b32b8144 | 20 | #include "io_context_pool.hpp" |
7c673cae FG |
21 | #include "request_handler.hpp" |
22 | ||
23 | namespace http { | |
24 | namespace server2 { | |
25 | ||
26 | /// The top-level class of the HTTP server. | |
27 | class server | |
28 | : private boost::noncopyable | |
29 | { | |
30 | public: | |
31 | /// Construct the server to listen on the specified TCP address and port, and | |
32 | /// serve up files from the given directory. | |
33 | explicit server(const std::string& address, const std::string& port, | |
b32b8144 | 34 | const std::string& doc_root, std::size_t io_context_pool_size); |
7c673cae | 35 | |
b32b8144 | 36 | /// Run the server's io_context loop. |
7c673cae FG |
37 | void run(); |
38 | ||
39 | private: | |
40 | /// Initiate an asynchronous accept operation. | |
41 | void start_accept(); | |
42 | ||
43 | /// Handle completion of an asynchronous accept operation. | |
44 | void handle_accept(const boost::system::error_code& e); | |
45 | ||
46 | /// Handle a request to stop the server. | |
47 | void handle_stop(); | |
48 | ||
b32b8144 FG |
49 | /// The pool of io_context objects used to perform asynchronous operations. |
50 | io_context_pool io_context_pool_; | |
7c673cae FG |
51 | |
52 | /// The signal_set is used to register for process termination notifications. | |
53 | boost::asio::signal_set signals_; | |
54 | ||
55 | /// Acceptor used to listen for incoming connections. | |
56 | boost::asio::ip::tcp::acceptor acceptor_; | |
57 | ||
58 | /// The next connection to be accepted. | |
59 | connection_ptr new_connection_; | |
60 | ||
61 | /// The handler for all incoming requests. | |
62 | request_handler request_handler_; | |
63 | }; | |
64 | ||
65 | } // namespace server2 | |
66 | } // namespace http | |
67 | ||
68 | #endif // HTTP_SERVER2_SERVER_HPP |