blob: d6e50a97f2d28b376aaa5cee25039b92a1c0bb57 [file] [log] [blame]
Zhenkai Zhua9a7e1d2013-02-25 18:29:07 -08001//
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_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
21namespace http {
22namespace server {
23
24/// The top-level class of the HTTP server.
25class server
26 : private boost::noncopyable
27{
28public:
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
34 /// Run the server's io_service loop.
35 void run();
36
Zhenkai Zhu8e3e9072013-02-28 15:40:51 -080037 ~server();
38
39private:
Zhenkai Zhu907cbaf2013-02-27 22:29:23 -080040 /// Handle a request to stop the server.
41 void handle_stop();
42
Zhenkai Zhua9a7e1d2013-02-25 18:29:07 -080043 /// Initiate an asynchronous accept operation.
44 void start_accept();
45
46 /// Handle completion of an asynchronous accept operation.
47 void handle_accept(const boost::system::error_code& e);
48
Zhenkai Zhua9a7e1d2013-02-25 18:29:07 -080049 /// The io_service used to perform asynchronous operations.
50 boost::asio::io_service io_service_;
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 connection manager which owns all live connections.
59 connection_manager connection_manager_;
60
61 /// The next connection to be accepted.
62 connection_ptr new_connection_;
63
64 /// The handler for all incoming requests.
65 request_handler request_handler_;
66};
67
68} // namespace server
69} // namespace http
70
71#endif // HTTP_SERVER_HPP