forked from boostorg/beast
Support BOOST_ASIO_NO_TS_EXECUTORS
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#include <boost/core/ignore_unused.hpp>
|
||||
#include <stdexcept>
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace boost {
|
||||
@@ -32,6 +33,52 @@ namespace beast {
|
||||
|
||||
namespace {
|
||||
|
||||
#if defined(BOOST_ASIO_NO_TS_EXECUTORS)
|
||||
struct ex1_type
|
||||
{
|
||||
|
||||
net::execution_context &
|
||||
query(net::execution::context_t c) const noexcept
|
||||
{ return *reinterpret_cast<net::execution_context *>(0); }
|
||||
|
||||
net::execution::blocking_t
|
||||
query(net::execution::blocking_t) const noexcept
|
||||
{ return net::execution::blocking; };
|
||||
|
||||
net::execution::outstanding_work_t
|
||||
query(net::execution::outstanding_work_t w) const noexcept
|
||||
{ return net::execution::outstanding_work; }
|
||||
|
||||
ex1_type
|
||||
require(net::execution::blocking_t::possibly_t b) const
|
||||
{ return *this; }
|
||||
|
||||
ex1_type
|
||||
require(net::execution::blocking_t::never_t b) const
|
||||
{ return *this; };
|
||||
|
||||
ex1_type
|
||||
prefer(net::execution::outstanding_work_t::untracked_t w) const
|
||||
{ return *this; };
|
||||
|
||||
ex1_type
|
||||
prefer(net::execution::outstanding_work_t::tracked_t w) const
|
||||
{ return *this; };
|
||||
|
||||
template<class F>
|
||||
void
|
||||
execute(F &&) const
|
||||
{}
|
||||
|
||||
bool
|
||||
operator==(ex1_type const &) const noexcept
|
||||
{ return true; }
|
||||
bool
|
||||
operator!=(ex1_type const &) const noexcept
|
||||
{ return false; }
|
||||
};
|
||||
BOOST_STATIC_ASSERT(net::execution::is_executor<ex1_type>::value);
|
||||
#else
|
||||
struct ex1_type
|
||||
{
|
||||
void* context() { return nullptr; }
|
||||
@@ -41,6 +88,9 @@ struct ex1_type
|
||||
template<class F> void post(F&&) {}
|
||||
template<class F> void defer(F&&) {}
|
||||
};
|
||||
BOOST_STATIC_ASSERT(net::is_executor<ex1_type>::value);
|
||||
#endif
|
||||
|
||||
|
||||
struct no_alloc
|
||||
{
|
||||
@@ -430,11 +480,13 @@ public:
|
||||
}
|
||||
{
|
||||
net::io_context ioc;
|
||||
async_base<
|
||||
test::handler,
|
||||
net::io_context::executor_type> op(
|
||||
test::any_handler(), ioc.get_executor());
|
||||
op.complete(false);
|
||||
auto op = new
|
||||
async_base<
|
||||
test::handler,
|
||||
net::io_context::executor_type>(
|
||||
test::any_handler(), ioc.get_executor());
|
||||
op->complete(false);
|
||||
delete op;
|
||||
ioc.run();
|
||||
}
|
||||
{
|
||||
@@ -506,12 +558,13 @@ public:
|
||||
net::io_context ioc1;
|
||||
net::io_context ioc2;
|
||||
auto h = net::bind_executor(ioc2, test::any_handler());
|
||||
stable_async_base<
|
||||
auto op = new stable_async_base<
|
||||
decltype(h),
|
||||
net::io_context::executor_type> op(
|
||||
net::io_context::executor_type>(
|
||||
std::move(h),
|
||||
ioc1.get_executor());
|
||||
op.complete(false);
|
||||
op->complete(false);
|
||||
delete op;
|
||||
BEAST_EXPECT(ioc1.run() == 0);
|
||||
BEAST_EXPECT(ioc2.run() == 1);
|
||||
}
|
||||
@@ -678,7 +731,9 @@ public:
|
||||
: base_type(std::move(handler), stream.get_executor())
|
||||
, stream_(stream)
|
||||
, repeats_(repeats)
|
||||
, data_(allocate_stable<temporary_data>(*this, std::move(message), stream.get_executor().context()))
|
||||
, data_(allocate_stable<temporary_data>(*this,
|
||||
std::move(message),
|
||||
net::query(stream.get_executor(), net::execution::context)))
|
||||
{
|
||||
(*this)(); // start the operation
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user