5 // Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11 #ifndef HTTP_CONNECTION_HPP
12 #define HTTP_CONNECTION_HPP
16 #include <boost/asio.hpp>
18 #include "request.hpp"
19 #include "request_handler.hpp"
20 #include "request_parser.hpp"
25 class connection_manager;
27 /// Represents a single connection from a client.
29 : public std::enable_shared_from_this<connection>
32 connection(const connection&) = delete;
33 connection& operator=(const connection&) = delete;
35 /// Construct a connection with the given socket.
36 explicit connection(boost::asio::ip::tcp::socket socket,
37 connection_manager& manager, request_handler& handler);
39 /// Start the first asynchronous operation for the connection.
42 /// Stop all asynchronous operations associated with the connection.
46 /// Perform an asynchronous read operation.
49 /// Perform an asynchronous write operation.
52 /// Socket for the connection.
53 boost::asio::ip::tcp::socket socket_;
55 /// The manager for this connection.
56 connection_manager& connection_manager_;
58 /// The handler used to process the incoming request.
59 request_handler& request_handler_;
61 /// Buffer for incoming data.
62 std::array<char, 8192> buffer_;
64 /// The incoming request.
67 /// The parser for the incoming request.
68 request_parser request_parser_;
70 /// The reply to be sent back to the client.
74 typedef std::shared_ptr<connection> connection_ptr;
79 #endif // HTTP_CONNECTION_HPP