Examples use bind_front_handler

This commit is contained in:
Vinnie Falco
2019-02-14 17:28:54 -08:00
parent 92add2afa6
commit 18447553ca
26 changed files with 248 additions and 397 deletions
@@ -89,11 +89,9 @@ public:
resolver_.async_resolve(
host,
port,
std::bind(
beast::bind_front_handler(
&session::on_resolve,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}
void
@@ -111,14 +109,13 @@ public:
beast::async_connect(
beast::get_lowest_layer(stream_),
results,
std::bind(
beast::bind_front_handler(
&session::on_connect,
shared_from_this(),
std::placeholders::_1));
shared_from_this()));
}
void
on_connect(beast::error_code ec)
on_connect(beast::error_code ec, tcp::resolver::results_type::endpoint_type)
{
if(ec)
return fail(ec, "connect");
@@ -126,10 +123,9 @@ public:
// Perform the SSL handshake
stream_.async_handshake(
ssl::stream_base::client,
std::bind(
beast::bind_front_handler(
&session::on_handshake,
shared_from_this(),
std::placeholders::_1));
shared_from_this()));
}
void
@@ -143,11 +139,9 @@ public:
// Send the HTTP request to the remote host
http::async_write(stream_, req_,
std::bind(
beast::bind_front_handler(
&session::on_write,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}
void
@@ -162,11 +156,9 @@ public:
// Receive the HTTP response
http::async_read(stream_, buffer_, res_,
std::bind(
beast::bind_front_handler(
&session::on_read,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}
void
@@ -187,10 +179,9 @@ public:
// Gracefully close the stream
stream_.async_shutdown(
std::bind(
beast::bind_front_handler(
&session::on_shutdown,
shared_from_this(),
std::placeholders::_1));
shared_from_this()));
}
void
@@ -76,11 +76,9 @@ public:
resolver_.async_resolve(
host,
port,
std::bind(
beast::bind_front_handler(
&session::on_resolve,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}
void
@@ -98,14 +96,13 @@ public:
beast::async_connect(
stream_,
results,
std::bind(
beast::bind_front_handler(
&session::on_connect,
shared_from_this(),
std::placeholders::_1));
shared_from_this()));
}
void
on_connect(beast::error_code ec)
on_connect(beast::error_code ec, tcp::resolver::results_type::endpoint_type)
{
if(ec)
return fail(ec, "connect");
@@ -115,11 +112,9 @@ public:
// Send the HTTP request to the remote host
http::async_write(stream_, req_,
std::bind(
beast::bind_front_handler(
&session::on_write,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}
void
@@ -134,11 +129,9 @@ public:
// Receive the HTTP response
http::async_read(stream_, buffer_, res_,
std::bind(
beast::bind_front_handler(
&session::on_read,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}
void
+12 -21
View File
@@ -217,10 +217,9 @@ public:
timer_.async_wait(
net::bind_executor(
strand_,
std::bind(
beast::bind_front_handler(
&worker::on_timer,
shared_from_this(),
std::placeholders::_1)));
shared_from_this())));
}
void
@@ -249,11 +248,9 @@ public:
"http",
net::bind_executor(
strand_,
std::bind(
beast::bind_front_handler(
&worker::on_resolve,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2)));
shared_from_this())));
}
void
@@ -277,18 +274,16 @@ public:
// Make the connection on the IP address we get from a lookup
net::async_connect(
socket_,
results.begin(),
results.end(),
results,
net::bind_executor(
strand_,
std::bind(
beast::bind_front_handler(
&worker::on_connect,
shared_from_this(),
std::placeholders::_1)));
shared_from_this())));
}
void
on_connect(beast::error_code ec)
on_connect(beast::error_code ec, tcp::resolver::results_type::endpoint_type)
{
if(ec)
{
@@ -309,11 +304,9 @@ public:
req_,
net::bind_executor(
strand_,
std::bind(
beast::bind_front_handler(
&worker::on_write,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2)));
shared_from_this())));
}
void
@@ -344,11 +337,9 @@ public:
res_,
net::bind_executor(
strand_,
std::bind(
beast::bind_front_handler(
&worker::on_read,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2)));
shared_from_this())));
}
void
@@ -248,11 +248,9 @@ class session : public std::enable_shared_from_this<session>
http::async_write(
self_.stream_,
*sp,
std::bind(
beast::bind_front_handler(
&session::on_write,
self_.shared_from_this(),
std::placeholders::_1,
std::placeholders::_2,
sp->need_eof()));
}
};
@@ -287,10 +285,9 @@ public:
// Perform the SSL handshake
stream_.async_handshake(
ssl::stream_base::server,
std::bind(
beast::bind_front_handler(
&session::on_handshake,
shared_from_this(),
std::placeholders::_1));
shared_from_this()));
}
void
@@ -314,11 +311,9 @@ public:
// Read a request
http::async_read(stream_, buffer_, req_,
std::bind(
beast::bind_front_handler(
&session::on_read,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}
void
@@ -341,9 +336,9 @@ public:
void
on_write(
bool close,
beast::error_code ec,
std::size_t bytes_transferred,
bool close)
std::size_t bytes_transferred)
{
boost::ignore_unused(bytes_transferred);
@@ -372,10 +367,9 @@ public:
// Perform the SSL shutdown
stream_.async_shutdown(
std::bind(
beast::bind_front_handler(
&session::on_shutdown,
shared_from_this(),
std::placeholders::_1));
shared_from_this()));
}
void
@@ -456,11 +450,9 @@ public:
do_accept()
{
acceptor_.async_accept(
std::bind(
beast::bind_front_handler(
&listener::on_accept,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}
void
@@ -244,11 +244,9 @@ class session : public std::enable_shared_from_this<session>
http::async_write(
self_.stream_,
*sp,
std::bind(
beast::bind_front_handler(
&session::on_write,
self_.shared_from_this(),
std::placeholders::_1,
std::placeholders::_2,
sp->need_eof()));
}
};
@@ -290,11 +288,9 @@ public:
// Read a request
http::async_read(stream_, buffer_, req_,
std::bind(
beast::bind_front_handler(
&session::on_read,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}
void
@@ -317,9 +313,9 @@ public:
void
on_write(
bool close,
beast::error_code ec,
std::size_t bytes_transferred,
bool close)
std::size_t bytes_transferred)
{
boost::ignore_unused(bytes_transferred);
@@ -416,11 +412,9 @@ public:
do_accept()
{
acceptor_.async_accept(
std::bind(
beast::bind_front_handler(
&listener::on_accept,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}
void
+13 -24
View File
@@ -266,11 +266,9 @@ class session
http::async_write(
self_.derived().stream(),
*sp,
std::bind(
beast::bind_front_handler(
&session::on_write,
self_.derived().shared_from_this(),
std::placeholders::_1,
std::placeholders::_2,
sp->need_eof()));
}
};
@@ -306,11 +304,9 @@ public:
derived().stream(),
buffer_,
req_,
std::bind(
beast::bind_front_handler(
&session::on_read,
derived().shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
derived().shared_from_this()));
}
void
@@ -333,9 +329,9 @@ public:
void
on_write(
bool close,
beast::error_code ec,
std::size_t bytes_transferred,
bool close)
std::size_t bytes_transferred)
{
boost::ignore_unused(bytes_transferred);
@@ -442,11 +438,9 @@ public:
stream_.async_handshake(
ssl::stream_base::server,
buffer_.data(),
std::bind(
beast::bind_front_handler(
&ssl_session::on_handshake,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}
void
on_handshake(
@@ -470,10 +464,9 @@ public:
// Perform the SSL shutdown
stream_.async_shutdown(
std::bind(
beast::bind_front_handler(
&ssl_session::on_shutdown,
shared_from_this(),
std::placeholders::_1));
shared_from_this()));
}
void
@@ -518,11 +511,9 @@ public:
async_detect_ssl(
stream_,
buffer_,
std::bind(
beast::bind_front_handler(
&detect_session::on_detect,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}
void
@@ -616,11 +607,9 @@ public:
do_accept()
{
acceptor_.async_accept(
std::bind(
beast::bind_front_handler(
&listener::on_accept,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}
void
@@ -251,11 +251,9 @@ class session
http::async_write(
self_.stream_,
*sp,
std::bind(
beast::bind_front_handler(
&session::loop,
self_.shared_from_this(),
std::placeholders::_1,
std::placeholders::_2,
sp->need_eof()));
}
};
@@ -283,15 +281,15 @@ public:
void
run()
{
loop({}, 0, false);
loop(false, {}, 0);
}
#include <boost/asio/yield.hpp>
void
loop(
bool close,
beast::error_code ec,
std::size_t bytes_transferred,
bool close)
std::size_t bytes_transferred)
{
boost::ignore_unused(bytes_transferred);
reenter(*this)
@@ -307,11 +305,9 @@ public:
// Read a request
yield http::async_read(stream_, buffer_, req_,
std::bind(
beast::bind_front_handler(
&session::loop,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2,
false));
if(ec == http::error::end_of_stream)
{
@@ -419,10 +415,9 @@ public:
{
yield acceptor_.async_accept(
socket_,
std::bind(
beast::bind_front_handler(
&listener::loop,
shared_from_this(),
std::placeholders::_1));
shared_from_this()));
if(ec)
{
fail(ec, "accept");