Imported Upstream version 1.51.0
[platform/upstream/boost.git] / doc / html / boost_asio / example / http / server2 / server.hpp
1 //
2 // server.hpp
3 // ~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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"
20 #include "io_service_pool.hpp"
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,
34       const std::string& doc_root, std::size_t io_service_pool_size);
35
36   /// Run the server's io_service loop.
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
49   /// The pool of io_service objects used to perform asynchronous operations.
50   io_service_pool io_service_pool_;
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