blob: 8a81b06cc58d48b45ebb5dc0a263e101194ed40b [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
Zhenkai Zhu377cbeb2013-02-28 16:36:26 -080034 ~server();
35
Zhenkai Zhua9a7e1d2013-02-25 18:29:07 -080036 /// Run the server's io_service loop.
37 void run();
38
Zhenkai Zhu907cbaf2013-02-27 22:29:23 -080039 /// Handle a request to stop the server.
40 void handle_stop();
41
Zhenkai Zhu377cbeb2013-02-28 16:36:26 -080042private:
43
Zhenkai Zhua9a7e1d2013-02-25 18:29:07 -080044 /// Initiate an asynchronous accept operation.
45 void start_accept();
46
47 /// Handle completion of an asynchronous accept operation.
48 void handle_accept(const boost::system::error_code& e);
49
Zhenkai Zhua9a7e1d2013-02-25 18:29:07 -080050 /// The io_service used to perform asynchronous operations.
51 boost::asio::io_service io_service_;
52
53 /// The signal_set is used to register for process termination notifications.
Alexander Afanasyevf8ff5e12013-07-11 13:57:32 -070054 // boost::asio::signal_set signals_;
Zhenkai Zhua9a7e1d2013-02-25 18:29:07 -080055
56 /// Acceptor used to listen for incoming connections.
57 boost::asio::ip::tcp::acceptor acceptor_;
58
59 /// The connection manager which owns all live connections.
60 connection_manager connection_manager_;
61
62 /// The next connection to be accepted.
63 connection_ptr new_connection_;
64
65 /// The handler for all incoming requests.
66 request_handler request_handler_;
67};
68
69} // namespace server
70} // namespace http
71
72#endif // HTTP_SERVER_HPP