| /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| /** |
| * Copyright (c) 2013-2016, Regents of the University of California. |
| * |
| * This file is part of ChronoShare, a decentralized file sharing application over NDN. |
| * |
| * ChronoShare is free software: you can redistribute it and/or modify it under the terms |
| * of the GNU General Public License as published by the Free Software Foundation, either |
| * version 3 of the License, or (at your option) any later version. |
| * |
| * ChronoShare is distributed in the hope that it will be useful, but WITHOUT ANY |
| * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| * PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| * |
| * You should have received copies of the GNU General Public License along with |
| * ChronoShare, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| * |
| * See AUTHORS.md for complete list of ChronoShare authors and contributors. |
| */ |
| // |
| // connection.hpp |
| // ~~~~~~~~~~~~~~ |
| // |
| // Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com) |
| // |
| // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| // |
| |
| #ifndef HTTP_CONNECTION_HPP |
| #define HTTP_CONNECTION_HPP |
| |
| #include <boost/asio.hpp> |
| #include <boost/array.hpp> |
| #include <boost/noncopyable.hpp> |
| #include <boost/shared_ptr.hpp> |
| #include <boost/enable_shared_from_this.hpp> |
| #include "reply.hpp" |
| #include "request.hpp" |
| #include "request_handler.hpp" |
| #include "request_parser.hpp" |
| |
| namespace http { |
| namespace server { |
| |
| class connection_manager; |
| |
| /// Represents a single connection from a client. |
| class connection |
| : public boost::enable_shared_from_this<connection>, |
| private boost::noncopyable |
| { |
| public: |
| /// Construct a connection with the given io_service. |
| explicit connection(boost::asio::io_service& io_service, |
| connection_manager& manager, request_handler& handler); |
| |
| /// Get the socket associated with the connection. |
| boost::asio::ip::tcp::socket& socket(); |
| |
| /// Start the first asynchronous operation for the connection. |
| void start(); |
| |
| /// Stop all asynchronous operations associated with the connection. |
| void stop(); |
| |
| private: |
| /// Handle completion of a read operation. |
| void handle_read(const boost::system::error_code& e, |
| std::size_t bytes_transferred); |
| |
| /// Handle completion of a write operation. |
| void handle_write(const boost::system::error_code& e); |
| |
| /// Socket for the connection. |
| boost::asio::ip::tcp::socket socket_; |
| |
| /// The manager for this connection. |
| connection_manager& connection_manager_; |
| |
| /// The handler used to process the incoming request. |
| request_handler& request_handler_; |
| |
| /// Buffer for incoming data. |
| boost::array<char, 8192> buffer_; |
| |
| /// The incoming request. |
| request request_; |
| |
| /// The parser for the incoming request. |
| request_parser request_parser_; |
| |
| /// The reply to be sent back to the client. |
| reply reply_; |
| }; |
| |
| typedef boost::shared_ptr<connection> connection_ptr; |
| |
| } // namespace server |
| } // namespace http |
| |
| #endif // HTTP_CONNECTION_HPP |