5 // Copyright (c) 2003-2012 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_SERVER2_SERVER_HPP
12 #define HTTP_SERVER2_SERVER_HPP
14 #include <boost/asio.hpp>
17 #include <boost/noncopyable.hpp>
18 #include <boost/shared_ptr.hpp>
19 #include "connection.hpp"
20 #include "io_service_pool.hpp"
21 #include "request_handler.hpp"
26 /// The top-level class of the HTTP server.
28 : private boost::noncopyable
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,
34 const std::string& doc_root, std::size_t io_service_pool_size);
36 /// Run the server's io_service loop.
40 /// Initiate an asynchronous accept operation.
43 /// Handle completion of an asynchronous accept operation.
44 void handle_accept(const boost::system::error_code& e);
46 /// Handle a request to stop the server.
49 /// The pool of io_service objects used to perform asynchronous operations.
50 io_service_pool io_service_pool_;
52 /// The signal_set is used to register for process termination notifications.
53 boost::asio::signal_set signals_;
55 /// Acceptor used to listen for incoming connections.
56 boost::asio::ip::tcp::acceptor acceptor_;
58 /// The next connection to be accepted.
59 connection_ptr new_connection_;
61 /// The handler for all incoming requests.
62 request_handler request_handler_;
65 } // namespace server2
68 #endif // HTTP_SERVER2_SERVER_HPP