forked from boostorg/beast
Examples use bind_front_handler
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace boost {
|
||||
namespace beast {
|
||||
namespace test {
|
||||
|
||||
// DEPRECATED
|
||||
class ws_echo_server
|
||||
{
|
||||
std::ostream& log_;
|
||||
|
||||
Reference in New Issue
Block a user