blob: cedb5934cf869d041a66a0ea813e1dd33feda2f4 [file] [log] [blame]
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2016, Regents of the University of California.
4 *
5 * This file is part of ChronoShare, a decentralized file sharing application over NDN.
6 *
7 * ChronoShare is free software: you can redistribute it and/or modify it under the terms
8 * of the GNU General Public License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
10 *
11 * ChronoShare is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License along with
16 * ChronoShare, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * See AUTHORS.md for complete list of ChronoShare authors and contributors.
19 */
Zhenkai Zhua9a7e1d2013-02-25 18:29:07 -080020//
21// server.hpp
22// ~~~~~~~~~~
23//
24// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
25//
26// Distributed under the Boost Software License, Version 1.0. (See accompanying
27// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
28//
29
30#ifndef HTTP_SERVER_HPP
31#define HTTP_SERVER_HPP
32
33#include <boost/asio.hpp>
34#include <string>
35#include <boost/noncopyable.hpp>
36#include "connection.hpp"
37#include "connection_manager.hpp"
38#include "request_handler.hpp"
39
40namespace http {
41namespace server {
42
43/// The top-level class of the HTTP server.
44class server
45 : private boost::noncopyable
46{
47public:
48 /// Construct the server to listen on the specified TCP address and port, and
49 /// serve up files from the given directory.
50 explicit server(const std::string& address, const std::string& port,
51 const std::string& doc_root);
52
Zhenkai Zhu377cbeb2013-02-28 16:36:26 -080053 ~server();
54
Zhenkai Zhua9a7e1d2013-02-25 18:29:07 -080055 /// Run the server's io_service loop.
56 void run();
57
Zhenkai Zhu907cbaf2013-02-27 22:29:23 -080058 /// Handle a request to stop the server.
59 void handle_stop();
60
Zhenkai Zhu377cbeb2013-02-28 16:36:26 -080061private:
62
Zhenkai Zhua9a7e1d2013-02-25 18:29:07 -080063 /// Initiate an asynchronous accept operation.
64 void start_accept();
65
66 /// Handle completion of an asynchronous accept operation.
67 void handle_accept(const boost::system::error_code& e);
68
Zhenkai Zhua9a7e1d2013-02-25 18:29:07 -080069 /// The io_service used to perform asynchronous operations.
70 boost::asio::io_service io_service_;
71
72 /// The signal_set is used to register for process termination notifications.
Alexander Afanasyevf8ff5e12013-07-11 13:57:32 -070073 // boost::asio::signal_set signals_;
Zhenkai Zhua9a7e1d2013-02-25 18:29:07 -080074
75 /// Acceptor used to listen for incoming connections.
76 boost::asio::ip::tcp::acceptor acceptor_;
77
78 /// The connection manager which owns all live connections.
79 connection_manager connection_manager_;
80
81 /// The next connection to be accepted.
82 connection_ptr new_connection_;
83
84 /// The handler for all incoming requests.
85 request_handler request_handler_;
86};
87
88} // namespace server
89} // namespace http
90
91#endif // HTTP_SERVER_HPP