Support BOOST_ASIO_NO_TS_EXECUTORS

This commit is contained in:
Richard Hodges committed 2020-07-04 07:35:14 +02:00
1 parent 5f1adfbc6d
commit 060f59685c
20 files changed
+285 -92

No files matched your search

+64 -9
View File
@@ -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
}
+1
View File
@@ -1226,6 +1226,7 @@ public:
{
return {};
}
void process_http_1 (tcp_stream& stream, net::yield_context yield)
{
flat_buffer buffer;
+8 -5
View File
@@ -80,11 +80,9 @@ public:
class test_executor
{
bind_handler_test& s_;
#if defined(BOOST_ASIO_NO_TS_EXECUTORS)
net::any_io_executor ex_;
#else
net::io_context::executor_type ex_;
#endif
// Storing the blocking property as a member is not strictly necessary,
// as we could simply forward the calls
@@ -97,6 +95,9 @@ public:
// outstanding_work property.
net::execution::blocking_t blocking_;
#else // defined(BOOST_ASIO_NO_TS_EXECUTORS)
net::io_context::executor_type ex_;
#endif // defined(BOOST_ASIO_NO_TS_EXECUTORS)
public:
test_executor(
test_executor const&) = default;
@@ -106,7 +107,9 @@ public:
net::io_context& ioc)
: s_(s)
, ex_(ioc.get_executor())
#if defined(BOOST_ASIO_NO_TS_EXECUTORS)
, blocking_(net::execution::blocking.possibly)
#endif
{
}
@@ -123,6 +126,7 @@ public:
}
#if defined(BOOST_ASIO_NO_TS_EXECUTORS)
net::execution_context& query(net::execution::context_t c) const noexcept
{
return net::query(ex_, c);
@@ -182,7 +186,6 @@ public:
}
}
#endif
#if !defined(BOOST_ASIO_NO_TS_EXECUTORS)
net::execution_context&
context() const noexcept
@@ -247,7 +250,7 @@ public:
BOOST_STATIC_ASSERT(std::is_nothrow_destructible<T>::value);
BOOST_STATIC_ASSERT(boost::asio::traits::equality_comparable<T>::is_valid);
BOOST_STATIC_ASSERT(boost::asio::traits::equality_comparable<T>::is_noexcept);
BOOST_STATIC_ASSERT(net::execution::is_executor_v<test_executor>);
BOOST_STATIC_ASSERT(net::execution::is_executor<test_executor>::value);
#else
BOOST_STATIC_ASSERT(net::is_executor<test_executor>::value);
#endif
+3 -4
View File
@@ -18,7 +18,6 @@
#include <boost/asio/buffer.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/read.hpp>
#include <boost/asio/spawn.hpp>
#include <boost/asio/strand.hpp>
#include <boost/optional.hpp>
#if BOOST_ASIO_HAS_CO_AWAIT
@@ -42,9 +41,10 @@ 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);
BEAST_EXPECT(&srs.get_executor().context() == &ioc);
BEAST_EXPECT(&net::query(srs.get_executor(), net::execution::context) == &ioc);
BEAST_EXPECT(
&srs.get_executor().context() == &srs2.get_executor().context());
&net::query(srs.get_executor(), net::execution::context) ==
&net::query(srs2.get_executor(), net::execution::context));
}
{
test::stream ts{ioc};
@@ -238,7 +238,6 @@ public:
{
testRead(yield);
});
testAsyncLoop();
#if BOOST_ASIO_HAS_CO_AWAIT
-1
View File
@@ -14,7 +14,6 @@
#include <boost/beast/core/error.hpp>
#include <boost/beast/core/stream_traits.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/asio/spawn.hpp>
#include <boost/asio/use_future.hpp>
namespace boost {
+17 -1
View File
@@ -57,7 +57,7 @@ class simple_executor
std::size_t id_;
public:
simple_executor()
simple_executor() noexcept
: id_([]
{
static std::size_t n = 0;
@@ -66,12 +66,19 @@ public:
{
}
#if defined(BOOST_ASIO_NO_TS_EXECUTORS)
void* query(net::execution::context_t) const { return nullptr; }
template<class F>
void execute(F&&) const {}
simple_executor prefer(net::execution::outstanding_work_t::tracked_t) const { return *this; }
#else
void* context() { return nullptr; }
void on_work_started() {}
void on_work_finished() {}
template<class F> void dispatch(F&&) {}
template<class F> void post(F&&) {}
template<class F> void defer(F&&) {}
#endif
friend
bool operator==(
@@ -90,6 +97,15 @@ public:
}
};
#if defined(BOOST_ASIO_NO_TS_EXECUTORS)
static_assert(net::execution::can_execute<simple_executor, net::execution::invocable_archetype>::value, "");
static_assert(std::is_nothrow_copy_constructible<simple_executor>::value, "");
static_assert(std::is_nothrow_destructible<simple_executor>::value, "");
static_assert(net::traits::equality_comparable<simple_executor>::is_valid, "");
static_assert(net::traits::equality_comparable<simple_executor>::is_noexcept, "");
static_assert(net::execution::is_executor<simple_executor>::value, "");
#endif
// A move-only handler
struct move_only_handler
{