9 socket_type&& sock, std::shared_ptr<request_dispatcher> dispatcher)
10 : sock_(
std::move(sock))
11 , dispatcher_(dispatcher)
12 , strand_(sock_.get_io_service())
15 <<
", handle=" <<
sock_.native_handle();
25 beast::http::async_read(
27 strand_.wrap([
self = shared_from_this()](
28 boost::system::error_code
const& ec) {
self->on_read(ec); }));
33 JB_LOG(
info) <<
"#" <<
id_ <<
" on_read: " << ec.message() <<
" [" 34 << ec.category().name() <<
"/" << ec.value() <<
"]";
41 res.set(beast::http::field::content_length, res.body.size());
44 auto ptr = std::make_shared<response_type>(std::move(res));
47 ptr,
self = shared_from_this()
48 ](boost::system::error_code
const& ec) {
self->on_write(ec); }));
53 JB_LOG(
info) <<
"#" <<
id_ <<
" on_write: " << ec.message() <<
" [" 54 << ec.category().name() <<
"/" << ec.value() <<
"]";
boost::asio::io_service::strand strand_
void on_read(boost::system::error_code const &ec)
Handle a completed HTTP request read.
void on_write(boost::system::error_code const &ec)
Handle a completed response write.
void run()
Asynchronously read a HTTP request for this connection.
static std::atomic< int > idgen
beast::http::response< beast::http::string_body > response_type
The response type used for JayBeams Embedded HTTP Servers.
boost::asio::ip::tcp::socket socket_type
The type of socket used for the connection.
connection(socket_type &&sock, std::shared_ptr< request_dispatcher > dispatcher)
Create a new connection.
std::shared_ptr< request_dispatcher > dispatcher_
The top-level namespace for the JayBeams library.