Examples use bind_front_handler

This commit is contained in:
Vinnie Falco
2019-02-14 16:20:27 -08:00
parent 92add2afa6
commit 18447553ca
26 changed files with 248 additions and 397 deletions

View File

@ -3,6 +3,7 @@ Version 215:
* basic_stream uses boost::shared_ptr
* Remove bind_back_handler
* bind_front_handler works with member functions
* Examples use bind_front_handler
--------------------------------------------------------------------------------

View File

@ -261,21 +261,18 @@ public:
// Set the control callback. This will be called
// on every incoming ping, pong, and close frame.
derived().ws().control_callback(
std::bind(
beast::bind_front_handler(
&websocket_session::on_control_callback,
this,
std::placeholders::_1,
std::placeholders::_2));
this));
// VFALCO What about the timer?
// Accept the websocket handshake
derived().ws().async_accept(
req,
std::bind(
beast::bind_front_handler(
&websocket_session::on_accept,
derived().shared_from_this(),
std::placeholders::_1));
derived().shared_from_this()));
}
void
@ -314,10 +311,9 @@ public:
// Now send the ping
derived().ws().async_ping({},
std::bind(
beast::bind_front_handler(
&websocket_session::on_ping,
derived().shared_from_this(),
std::placeholders::_1));
derived().shared_from_this()));
}
else
{
@ -334,10 +330,9 @@ public:
timer_.async_wait(
net::bind_executor(
derived().ws().get_executor(), // use the strand
std::bind(
beast::bind_front_handler(
&websocket_session::on_timer,
derived().shared_from_this(),
std::placeholders::_1)));
derived().shared_from_this())));
}
// Called to indicate activity from the remote peer
@ -393,11 +388,9 @@ public:
// Read a message into our buffer
derived().ws().async_read(
buffer_,
std::bind(
beast::bind_front_handler(
&websocket_session::on_read,
derived().shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
derived().shared_from_this()));
}
void
@ -425,11 +418,9 @@ public:
derived().ws().text(derived().ws().got_text());
derived().ws().async_write(
buffer_.data(),
std::bind(
beast::bind_front_handler(
&websocket_session::on_write,
derived().shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
derived().shared_from_this()));
}
void
@ -510,10 +501,9 @@ public:
// Close the WebSocket Connection
ws_.async_close(
websocket::close_code::normal,
std::bind(
beast::bind_front_handler(
&plain_websocket_session::on_close,
shared_from_this(),
std::placeholders::_1));
shared_from_this()));
}
void
@ -581,10 +571,9 @@ public:
// Perform the SSL shutdown
ws_.next_layer().async_shutdown(
std::bind(
beast::bind_front_handler(
&ssl_websocket_session::on_shutdown,
shared_from_this(),
std::placeholders::_1));
shared_from_this()));
}
void
@ -724,10 +713,9 @@ class http_session
http::async_write(
self_.derived().stream(),
msg_,
std::bind(
beast::bind_front_handler(
&http_session::on_write,
self_.derived().shared_from_this(),
std::placeholders::_1,
msg_.need_eof()));
}
};
@ -780,15 +768,16 @@ public:
derived().stream(),
buffer_,
req_,
std::bind(
beast::bind_front_handler(
&http_session::on_read,
derived().shared_from_this(),
std::placeholders::_1));
derived().shared_from_this()));
}
void
on_read(beast::error_code ec)
on_read(beast::error_code ec, std::size_t bytes_transferred)
{
boost::ignore_unused(bytes_transferred);
// This means they closed the connection
if(ec == http::error::end_of_stream)
return derived().do_eof();
@ -814,8 +803,10 @@ public:
}
void
on_write(beast::error_code ec, bool close)
on_write(bool close, beast::error_code ec, std::size_t bytes_transferred)
{
boost::ignore_unused(bytes_transferred);
// Happens when the timer closes the socket
if(ec == net::error::operation_aborted)
return;
@ -882,7 +873,7 @@ public:
if(! stream_.get_executor().running_in_this_thread())
return net::post(
stream_.get_executor(),
std::bind(
beast::bind_front_handler(
&plain_http_session::run,
shared_from_this()));
@ -958,7 +949,7 @@ public:
if(! stream_.get_executor().running_in_this_thread())
return net::post(
stream_.get_executor(),
std::bind(
beast::bind_front_handler(
&ssl_http_session::run,
shared_from_this()));
@ -970,11 +961,9 @@ public:
stream_.async_handshake(
ssl::stream_base::server,
buffer_.data(),
std::bind(
beast::bind_front_handler(
&ssl_http_session::on_handshake,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}
void
on_handshake(
@ -1000,10 +989,9 @@ public:
// Perform the SSL shutdown
stream_.async_shutdown(
std::bind(
beast::bind_front_handler(
&ssl_http_session::on_shutdown,
shared_from_this(),
std::placeholders::_1));
shared_from_this()));
}
void
@ -1052,11 +1040,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));
this->shared_from_this()));
}
void
@ -1150,11 +1136,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

View File

@ -243,11 +243,9 @@ public:
// Set the control callback. This will be called
// on every incoming ping, pong, and close frame.
ws_.control_callback(
std::bind(
beast::bind_front_handler(
&websocket_session::on_control_callback,
this,
std::placeholders::_1,
std::placeholders::_2));
this));
// Run the timer. The timer is operated
// continuously, this simplifies the code.
@ -259,10 +257,9 @@ public:
// Accept the websocket handshake
ws_.async_accept(
req,
std::bind(
beast::bind_front_handler(
&websocket_session::on_accept,
shared_from_this(),
std::placeholders::_1));
shared_from_this()));
}
void
@ -301,10 +298,9 @@ public:
// Now send the ping
ws_.async_ping({},
std::bind(
beast::bind_front_handler(
&websocket_session::on_ping,
shared_from_this(),
std::placeholders::_1));
shared_from_this()));
}
else
{
@ -324,10 +320,9 @@ public:
timer_.async_wait(
net::bind_executor(
ws_.get_executor(), // use the strand
std::bind(
beast::bind_front_handler(
&websocket_session::on_timer,
shared_from_this(),
std::placeholders::_1)));
shared_from_this())));
}
// Called to indicate activity from the remote peer
@ -383,11 +378,9 @@ public:
// Read a message into our buffer
ws_.async_read(
buffer_,
std::bind(
beast::bind_front_handler(
&websocket_session::on_read,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}
void
@ -415,11 +408,9 @@ public:
ws_.text(ws_.got_text());
ws_.async_write(
buffer_.data(),
std::bind(
beast::bind_front_handler(
&websocket_session::on_write,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}
void
@ -520,10 +511,9 @@ class http_session : public std::enable_shared_from_this<http_session>
http::async_write(
self_.stream_,
msg_,
std::bind(
beast::bind_front_handler(
&http_session::on_write,
self_.shared_from_this(),
std::placeholders::_1,
msg_.need_eof()));
}
};
@ -584,15 +574,16 @@ public:
// Read a request
http::async_read(stream_, buffer_, req_,
std::bind(
beast::bind_front_handler(
&http_session::on_read,
shared_from_this(),
std::placeholders::_1));
shared_from_this()));
}
void
on_read(beast::error_code ec)
on_read(beast::error_code ec, std::size_t bytes_transferred)
{
boost::ignore_unused(bytes_transferred);
// This means they closed the connection
if(ec == http::error::end_of_stream)
return do_close();
@ -618,8 +609,10 @@ public:
}
void
on_write(beast::error_code ec, bool close)
on_write(bool close, beast::error_code ec, std::size_t bytes_transferred)
{
boost::ignore_unused(bytes_transferred);
// Happens when the timer closes the socket
if(ec == net::error::operation_aborted)
return;
@ -720,11 +713,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

View File

@ -287,8 +287,8 @@ async_detect_ssl(
AsyncReadStream,
DynamicBuffer,
BOOST_ASIO_HANDLER_TYPE(
CompletionToken, void(beast::error_code, boost::tribool))>{
stream, buffer, init.completion_handler}(beast::error_code{}, 0);
CompletionToken, void(beast::error_code, boost::tribool))>(
stream, buffer, std::move(init.completion_handler))(beast::error_code{}, 0);
// This hook lets the caller see a return value when appropriate.
// For example this might return std::future<error_code, boost::tribool> if

View File

@ -389,7 +389,7 @@ public:
template<class... Args>
void
operator()(Args&&... args) const
operator()(Args&&... args)
{
h_(std::forward<Args>(args)...);
}

View File

@ -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

View File

@ -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

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

View File

@ -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

View File

@ -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

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

View File

@ -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");

View File

@ -75,11 +75,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
@ -97,14 +95,13 @@ public:
beast::async_connect(
beast::get_lowest_layer(ws_),
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,10 +112,9 @@ public:
// Perform the SSL handshake
ws_.next_layer().async_handshake(
ssl::stream_base::client,
std::bind(
beast::bind_front_handler(
&session::on_ssl_handshake,
shared_from_this(),
std::placeholders::_1));
shared_from_this()));
}
void
@ -129,10 +125,9 @@ public:
// Perform the websocket handshake
ws_.async_handshake(host_, "/",
std::bind(
beast::bind_front_handler(
&session::on_handshake,
shared_from_this(),
std::placeholders::_1));
shared_from_this()));
}
void
@ -144,11 +139,9 @@ public:
// Send the message
ws_.async_write(
net::buffer(text_),
std::bind(
beast::bind_front_handler(
&session::on_write,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}
void
@ -164,11 +157,9 @@ public:
// Read a message into our buffer
ws_.async_read(
buffer_,
std::bind(
beast::bind_front_handler(
&session::on_read,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}
void
@ -183,10 +174,9 @@ public:
// Close the WebSocket connection
ws_.async_close(websocket::close_code::normal,
std::bind(
beast::bind_front_handler(
&session::on_close,
shared_from_this(),
std::placeholders::_1));
shared_from_this()));
}
void

View File

@ -70,11 +70,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
@ -92,24 +90,22 @@ public:
beast::async_connect(
beast::get_lowest_layer(ws_),
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");
// Perform the websocket handshake
ws_.async_handshake(host_, "/",
std::bind(
beast::bind_front_handler(
&session::on_handshake,
shared_from_this(),
std::placeholders::_1));
shared_from_this()));
}
void
@ -121,11 +117,9 @@ public:
// Send the message
ws_.async_write(
net::buffer(text_),
std::bind(
beast::bind_front_handler(
&session::on_write,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}
void
@ -141,11 +135,9 @@ public:
// Read a message into our buffer
ws_.async_read(
buffer_,
std::bind(
beast::bind_front_handler(
&session::on_read,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}
void
@ -160,10 +152,9 @@ public:
// Close the WebSocket connection
ws_.async_close(websocket::close_code::normal,
std::bind(
beast::bind_front_handler(
&session::on_close,
shared_from_this(),
std::placeholders::_1));
shared_from_this()));
}
void

View File

@ -69,10 +69,9 @@ public:
// Perform the SSL handshake
ws_.next_layer().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
@ -83,10 +82,9 @@ public:
// Accept the websocket handshake
ws_.async_accept(
std::bind(
beast::bind_front_handler(
&session::on_accept,
shared_from_this(),
std::placeholders::_1));
shared_from_this()));
}
void
@ -105,11 +103,9 @@ public:
// Read a message into our buffer
ws_.async_read(
buffer_,
std::bind(
beast::bind_front_handler(
&session::on_read,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}
void
@ -130,11 +126,9 @@ public:
ws_.text(ws_.got_text());
ws_.async_write(
buffer_.data(),
std::bind(
beast::bind_front_handler(
&session::on_write,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}
void
@ -220,11 +214,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

View File

@ -60,10 +60,9 @@ public:
{
// Accept the websocket handshake
ws_.async_accept(
std::bind(
beast::bind_front_handler(
&session::on_accept,
shared_from_this(),
std::placeholders::_1));
shared_from_this()));
}
void
@ -82,11 +81,9 @@ public:
// Read a message into our buffer
ws_.async_read(
buffer_,
std::bind(
beast::bind_front_handler(
&session::on_read,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}
void
@ -107,11 +104,9 @@ public:
ws_.text(ws_.got_text());
ws_.async_write(
buffer_.data(),
std::bind(
beast::bind_front_handler(
&session::on_write,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}
void
@ -194,11 +189,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

View File

@ -206,11 +206,9 @@ run()
// Read a request
http::async_read(stream_, buffer_, req_,
std::bind(
beast::bind_front_handler(
&http_session::on_read,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}
// Report a failure
@ -348,9 +346,7 @@ on_write(beast::error_code ec, std::size_t, bool close)
// Read another request
http::async_read(stream_, buffer_, req_,
std::bind(
beast::bind_front_handler(
&http_session::on_read,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}

View File

@ -61,11 +61,9 @@ run()
{
// Start accepting a connection
acceptor_.async_accept(
std::bind(
beast::bind_front_handler(
&listener::on_accept,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}
// Report a failure
@ -94,9 +92,7 @@ on_accept(beast::error_code ec, tcp::socket socket)
// Accept another connection
acceptor_.async_accept(
std::bind(
beast::bind_front_handler(
&listener::on_accept,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}

View File

@ -52,11 +52,9 @@ on_accept(beast::error_code ec)
// Read a message
ws_.async_read(
buffer_,
std::bind(
beast::bind_front_handler(
&websocket_session::on_read,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}
void
@ -76,11 +74,9 @@ on_read(beast::error_code ec, std::size_t)
// Read another message
ws_.async_read(
buffer_,
std::bind(
beast::bind_front_handler(
&websocket_session::on_read,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}
void
@ -93,7 +89,7 @@ send(boost::shared_ptr<std::string const> const& ss)
if(! ws_.get_executor().running_in_this_thread())
return net::post(
ws_.get_executor(),
std::bind(
beast::bind_front_handler(
&websocket_session::send,
shared_from_this(),
ss));
@ -108,11 +104,9 @@ send(boost::shared_ptr<std::string const> const& ss)
// We are not currently writing, so send this immediately
ws_.async_write(
net::buffer(*queue_.front()),
std::bind(
beast::bind_front_handler(
&websocket_session::on_write,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}
void
@ -130,9 +124,7 @@ on_write(beast::error_code ec, std::size_t)
if(! queue_.empty())
ws_.async_write(
net::buffer(*queue_.front()),
std::bind(
beast::bind_front_handler(
&websocket_session::on_write,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}

View File

@ -60,10 +60,9 @@ run(http::request<Body, http::basic_fields<Allocator>> req)
// Accept the websocket handshake
ws_.async_accept(
req,
std::bind(
beast::bind_front_handler(
&websocket_session::on_accept,
shared_from_this(),
std::placeholders::_1));
shared_from_this()));
}
#endif

View File

@ -131,9 +131,9 @@ do_sync_listen(
if(ec)
return fail(ec, "accept");
std::thread{std::bind(
std::thread(std::bind(
&do_sync_session,
ws_type(std::move(socket)))}.detach();
ws_type(std::move(socket)))).detach();
}
}
@ -165,10 +165,9 @@ public:
res.set(http::field::server,
"Boost.Beast/" + std::to_string(BOOST_BEAST_VERSION) + "-Async");
},
std::bind(
beast::bind_front_handler(
&async_session::on_accept,
shared_from_this(),
std::placeholders::_1));
shared_from_this()));
}
void
@ -187,11 +186,9 @@ public:
// Read a message into our buffer
ws_.async_read(
buffer_,
std::bind(
beast::bind_front_handler(
&async_session::on_read,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}
void
@ -212,11 +209,9 @@ public:
ws_.text(ws_.got_text());
ws_.async_write(
buffer_.data(),
std::bind(
beast::bind_front_handler(
&async_session::on_write,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}
void
@ -297,11 +292,9 @@ public:
do_accept()
{
acceptor_.async_accept(
std::bind(
beast::bind_front_handler(
&async_listener::on_accept,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}
void
@ -428,7 +421,7 @@ int main(int argc, char* argv[])
net::io_context ioc{threads};
// Create sync port
std::thread(std::bind(
std::thread(beast::bind_front_handler(
&do_sync_listen,
std::ref(ioc),
tcp::endpoint{

View File

@ -261,19 +261,16 @@ private:
if(s_.empty())
socket_.async_wait(
net::socket_base::wait_read,
std::bind(
bind_front_handler(
&session::on_read,
shared_from_this(),
std::placeholders::_1));
shared_from_this()));
else
net::async_write(
socket_,
net::const_buffer(s_.data(), s_.size()),
std::bind(
bind_front_handler(
&session::on_write,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}
protected:

View File

@ -12,8 +12,9 @@
#include <boost/beast/core/multi_buffer.hpp>
#include <boost/beast/_experimental/test/stream.hpp>
#include <boost/beast/test/yield_to.hpp>
#include <boost/beast/_experimental/unit_test/suite.hpp>
#include <boost/beast/core/bind_handler.hpp>
#include <boost/beast/test/yield_to.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/read.hpp>
@ -104,11 +105,9 @@ public:
brs_->buffer().prepare(5), net::buffer("Hello", 5)));
net::async_read(*brs_,
net::buffer(&s_[0], s_.size()),
std::bind(
bind_front_handler(
&loop::on_read,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
shared_from_this()));
}
};

View File

@ -10,6 +10,7 @@
#ifndef BEAST_TEST_WEBSOCKET_TEST_HPP
#define BEAST_TEST_WEBSOCKET_TEST_HPP
#include <boost/beast/core/bind_handler.hpp>
#include <boost/beast/core/buffer_size.hpp>
#include <boost/beast/core/buffers_prefix.hpp>
#include <boost/beast/core/buffers_to_string.hpp>
@ -131,10 +132,9 @@ public:
async_handshake()
{
ws_.async_handshake("localhost", "/",
std::bind(
bind_front_handler(
&echo_server::on_handshake,
this,
std::placeholders::_1));
this));
}
void
@ -146,10 +146,9 @@ public:
if(ws_.is_open())
{
ws_.async_close({},
std::bind(
bind_front_handler(
&echo_server::on_close,
this,
std::placeholders::_1));
this));
}
else
{
@ -192,10 +191,10 @@ public:
void
do_accept()
{
ws_.async_accept(std::bind(
&echo_server::on_accept,
this,
std::placeholders::_1));
ws_.async_accept(
bind_front_handler(
&echo_server::on_accept,
this));
}
void
@ -216,10 +215,9 @@ public:
if(close_)
{
return ws_.async_close({},
std::bind(
bind_front_handler(
&echo_server::on_close,
this,
std::placeholders::_1));
this));
}
do_read();
@ -229,27 +227,25 @@ public:
do_read()
{
ws_.async_read(buffer_,
std::bind(
beast::bind_front_handler(
&echo_server::on_read,
this,
std::placeholders::_1));
this));
}
void
on_read(error_code ec)
on_read(error_code ec, std::size_t)
{
if(ec)
return fail(ec);
ws_.text(ws_.got_text());
ws_.async_write(buffer_.data(),
std::bind(
beast::bind_front_handler(
&echo_server::on_write,
this,
std::placeholders::_1));
this));
}
void
on_write(error_code ec)
on_write(error_code ec, std::size_t)
{
if(ec)
return fail(ec);

View File

@ -153,10 +153,9 @@ public:
run()
{
ws_.next_layer().async_connect(ep_,
alloc_.wrap(std::bind(
alloc_.wrap(beast::bind_front_handler(
&connection::on_connect,
shared_from_this(),
std::placeholders::_1)));
shared_from_this())));
}
private:
@ -169,10 +168,9 @@ private:
ws_.async_handshake(
ep_.address().to_string() + ":" + std::to_string(ep_.port()),
"/",
alloc_.wrap(std::bind(
alloc_.wrap(beast::bind_front_handler(
&connection::on_handshake,
shared_from_this(),
std::placeholders::_1)));
shared_from_this())));
}
void
@ -191,14 +189,13 @@ private:
double(4) / beast::buffer_size(tb_)};
ws_.async_write_some(true,
beast::buffers_prefix(dist(rng_), tb_),
alloc_.wrap(std::bind(
alloc_.wrap(beast::bind_front_handler(
&connection::on_write,
shared_from_this(),
std::placeholders::_1)));
shared_from_this())));
}
void
on_write(beast::error_code ec)
on_write(beast::error_code ec, std::size_t)
{
if(ec)
return fail(ec, "write");
@ -207,24 +204,22 @@ private:
return do_read();
ws_.async_close({},
alloc_.wrap(std::bind(
alloc_.wrap(beast::bind_front_handler(
&connection::on_close,
shared_from_this(),
std::placeholders::_1)));
shared_from_this())));
}
void
do_read()
{
ws_.async_read(buffer_,
alloc_.wrap(std::bind(
alloc_.wrap(beast::bind_front_handler(
&connection::on_read,
shared_from_this(),
std::placeholders::_1)));
shared_from_this())));
}
void
on_read(beast::error_code ec)
on_read(beast::error_code ec, std::size_t)
{
if(ec)
return fail(ec, "read");

View File

@ -25,6 +25,7 @@ namespace boost {
namespace beast {
namespace test {
// DEPRECATED
class ws_echo_server
{
std::ostream& log_;