The top-level coroutine of the HTTP server.
| 26 | |
| 27 | /// The top-level coroutine of the HTTP server. |
| 28 | class server : boost::asio::coroutine |
| 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(boost::asio::io_context& io_context, |
| 34 | const std::string& address, const std::string& port, |
| 35 | std::function<void(const request&, reply&)> request_handler); |
| 36 | |
| 37 | /// Perform work associated with the server. |
| 38 | void operator()( |
| 39 | boost::system::error_code ec = boost::system::error_code(), |
| 40 | std::size_t length = 0); |
| 41 | |
| 42 | private: |
| 43 | typedef boost::asio::ip::tcp tcp; |
| 44 | |
| 45 | /// The user-supplied handler for all incoming requests. |
| 46 | std::function<void(const request&, reply&)> request_handler_; |
| 47 | |
| 48 | /// Acceptor used to listen for incoming connections. |
| 49 | std::shared_ptr<tcp::acceptor> acceptor_; |
| 50 | |
| 51 | /// The current connection from a client. |
| 52 | std::shared_ptr<tcp::socket> socket_; |
| 53 | |
| 54 | /// Buffer for incoming data. |
| 55 | std::shared_ptr<std::array<char, 8192>> buffer_; |
| 56 | |
| 57 | /// The incoming request. |
| 58 | std::shared_ptr<request> request_; |
| 59 | |
| 60 | /// Whether the request is valid or not. |
| 61 | request_parser::result_type parse_result_; |
| 62 | |
| 63 | /// The parser for the incoming request. |
| 64 | request_parser request_parser_; |
| 65 | |
| 66 | /// The reply to be sent back to the client. |
| 67 | std::shared_ptr<reply> reply_; |
| 68 | }; |
| 69 | |
| 70 | } // namespace server4 |
| 71 | } // namespace http |