diff options
author | 2016-11-07 10:42:23 +0100 | |
---|---|---|
committer | 2016-11-07 10:42:23 +0100 | |
commit | fc58a0bec8bf779af3afecbc6ca59a7b9c9c0b67 (patch) | |
tree | 011e6d736c6e191f130c066a860e7fda9d0e0014 /src/lib/http/connection.hpp | |
parent | ce0e6e6a3e114625e6b33a2ab75489a5b0cba17b (diff) |
Added basic HTTP server, not active yet, based on ASIO example with small refactoring included (nw)
Diffstat (limited to 'src/lib/http/connection.hpp')
-rw-r--r-- | src/lib/http/connection.hpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/lib/http/connection.hpp b/src/lib/http/connection.hpp new file mode 100644 index 00000000000..6ad1768242e --- /dev/null +++ b/src/lib/http/connection.hpp @@ -0,0 +1,72 @@ +// license:Boost +// copyright-holders:Christopher M. Kohlhoff + +#ifndef HTTP_CONNECTION_HPP +#define HTTP_CONNECTION_HPP + +#include <array> +#include <memory> +#include "asio.h" +#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 std::enable_shared_from_this<connection> +{ +public: + connection(const connection&) = delete; + connection& operator=(const connection&) = delete; + + /// Construct a connection with the given socket. + explicit connection(asio::ip::tcp::socket socket, + connection_manager& manager, request_handler& handler); + + /// Start the first asynchronous operation for the connection. + void start(); + + /// Stop all asynchronous operations associated with the connection. + void stop(); + +private: + /// Perform an asynchronous read operation. + void do_read(); + + /// Perform an asynchronous write operation. + void do_write(); + + /// Socket for the connection. + asio::ip::tcp::socket m_socket; + + /// The manager for this connection. + connection_manager& m_connection_manager; + + /// The handler used to process the incoming request. + request_handler& m_request_handler; + + /// Buffer for incoming data. + std::array<char, 8192> m_buffer; + + /// The incoming request. + request m_request; + + /// The parser for the incoming request. + request_parser m_request_parser; + + /// The reply to be sent back to the client. + reply m_reply; +}; + +typedef std::shared_ptr<connection> connection_ptr; + +} // namespace server +} // namespace http + +#endif // HTTP_CONNECTION_HPP |