Add executor rebind to test::stream

closes #2139
This commit is contained in:
Richard Hodges committed 2020-12-16 21:11:29 +01:00
1 parent a87330e53f
commit 8913a3cd21
13 files changed
+619 -400

No files matched your search

+10 -4
View File
@@ -34,12 +34,18 @@ namespace beast {
namespace {
#if defined(BOOST_ASIO_NO_TS_EXECUTORS)
static struct ex1_context : net::execution_context
{
} ex1ctx;
struct ex1_type
{
net::execution_context &
query(net::execution::context_t c) const noexcept
{ return *reinterpret_cast<net::execution_context *>(0); }
{ return *reinterpret_cast<net::execution_context *>(&ex1ctx); }
net::execution::blocking_t
query(net::execution::blocking_t) const noexcept
@@ -716,9 +722,9 @@ public:
net::steady_timer timer;
temporary_data(std::string message_, net::io_context& ctx)
temporary_data(std::string message_, net::any_io_executor ex)
: message(std::move(message_))
, timer(ctx)
, timer(std::move(ex))
{
}
};
@@ -733,7 +739,7 @@ public:
, repeats_(repeats)
, data_(allocate_stable<temporary_data>(*this,
std::move(message),
net::query(stream.get_executor(), net::execution::context)))
stream.get_executor()))
{
(*this)(); // start the operation
}
+9
View File
@@ -16,7 +16,9 @@
#include <boost/beast/core/bind_handler.hpp>
#include <boost/beast/test/yield_to.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/asio/execution.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/any_io_executor.hpp>
#include <boost/asio/read.hpp>
#include <boost/asio/strand.hpp>
#include <boost/optional.hpp>
@@ -41,10 +43,17 @@ public:
buffered_read_stream<test::stream, multi_buffer> srs(ioc);
buffered_read_stream<test::stream, multi_buffer> srs2(std::move(srs));
srs = std::move(srs2);
#if defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT)
BEAST_EXPECT(&srs.get_executor().context() == &ioc);
BEAST_EXPECT(
&srs.get_executor().context() ==
&srs2.get_executor().context());
#else
BEAST_EXPECT(&net::query(srs.get_executor(), net::execution::context) == &ioc);
BEAST_EXPECT(
&net::query(srs.get_executor(), net::execution::context) ==
&net::query(srs2.get_executor(), net::execution::context));
#endif
}
{
test::stream ts{ioc};