Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame^] | 1 | /* -*- 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 Zhu | a9a7e1d | 2013-02-25 18:29:07 -0800 | [diff] [blame] | 20 | // |
| 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 | |
| 40 | namespace http { |
| 41 | namespace server { |
| 42 | |
| 43 | /// The top-level class of the HTTP server. |
| 44 | class server |
| 45 | : private boost::noncopyable |
| 46 | { |
| 47 | public: |
| 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 Zhu | 377cbeb | 2013-02-28 16:36:26 -0800 | [diff] [blame] | 53 | ~server(); |
| 54 | |
Zhenkai Zhu | a9a7e1d | 2013-02-25 18:29:07 -0800 | [diff] [blame] | 55 | /// Run the server's io_service loop. |
| 56 | void run(); |
| 57 | |
Zhenkai Zhu | 907cbaf | 2013-02-27 22:29:23 -0800 | [diff] [blame] | 58 | /// Handle a request to stop the server. |
| 59 | void handle_stop(); |
| 60 | |
Zhenkai Zhu | 377cbeb | 2013-02-28 16:36:26 -0800 | [diff] [blame] | 61 | private: |
| 62 | |
Zhenkai Zhu | a9a7e1d | 2013-02-25 18:29:07 -0800 | [diff] [blame] | 63 | /// 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 Zhu | a9a7e1d | 2013-02-25 18:29:07 -0800 | [diff] [blame] | 69 | /// 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 Afanasyev | f8ff5e1 | 2013-07-11 13:57:32 -0700 | [diff] [blame] | 73 | // boost::asio::signal_set signals_; |
Zhenkai Zhu | a9a7e1d | 2013-02-25 18:29:07 -0800 | [diff] [blame] | 74 | |
| 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 |