1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
// Copyright Maarten L. Hekkelman, Radboud University 2008-2013.
// Copyright Maarten L. Hekkelman, 2014-2022
// 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)
#pragma once
/// \file
/// definition of the zeep::http::connection class, that handles HTTP connections
#include <zeep/config.hpp>
#include <memory>
#include <boost/asio/streambuf.hpp>
#include <boost/asio/posix/stream_descriptor.hpp>
#include <zeep/http/message-parser.hpp>
namespace zeep::http
{
class basic_server;
/// The HTTP server implementation of libzeep is inspired by the example code
/// as provided by boost::asio. These objects are not to be used directly.
class connection
: public std::enable_shared_from_this<connection>
{
public:
connection(connection &) = delete;
connection& operator=(connection &) = delete;
connection(boost::asio::io_context& service, basic_server& handler);
void start();
void handle_read(boost::system::error_code ec, size_t bytes_transferred);
void handle_write(boost::system::error_code ec, size_t bytes_transferred);
boost::asio::ip::tcp::socket& get_socket() { return m_socket; }
private:
boost::asio::ip::tcp::socket m_socket;
basic_server& m_server;
reply m_reply;
request_parser m_request_parser;
bool m_keep_alive = false;
boost::asio::streambuf m_buffer;
boost::asio::streambuf::mutable_buffers_type m_bufs;
};
} // namespace zeep::http
|