Specialize asio::associator for bind_wrapper and bind_front_wrapper

This commit is contained in:
Mohammad Nejati
2023-12-28 19:49:45 +00:00
committed by Mohammad Nejati
parent b1779ced98
commit 3df5d980d0
4 changed files with 40 additions and 117 deletions

View File

@@ -15,6 +15,7 @@
#include <boost/beast/core/detail/service_base.hpp> #include <boost/beast/core/detail/service_base.hpp>
#include <boost/beast/core/detail/is_invocable.hpp> #include <boost/beast/core/detail/is_invocable.hpp>
#include <boost/asio/any_io_executor.hpp> #include <boost/asio/any_io_executor.hpp>
#include <boost/asio/associated_cancellation_slot.hpp>
#include <boost/asio/dispatch.hpp> #include <boost/asio/dispatch.hpp>
#include <boost/asio/post.hpp> #include <boost/asio/post.hpp>
#include <mutex> #include <mutex>

View File

@@ -17,6 +17,7 @@
#include <boost/beast/core/detail/filtering_cancellation_slot.hpp> #include <boost/beast/core/detail/filtering_cancellation_slot.hpp>
#include <boost/beast/core/detail/work_guard.hpp> #include <boost/beast/core/detail/work_guard.hpp>
#include <boost/asio/associated_allocator.hpp> #include <boost/asio/associated_allocator.hpp>
#include <boost/asio/associated_cancellation_slot.hpp>
#include <boost/asio/associated_executor.hpp> #include <boost/asio/associated_executor.hpp>
#include <boost/asio/associated_immediate_executor.hpp> #include <boost/asio/associated_immediate_executor.hpp>
#include <boost/asio/bind_executor.hpp> #include <boost/asio/bind_executor.hpp>

View File

@@ -12,9 +12,7 @@
#include <boost/beast/core/error.hpp> #include <boost/beast/core/error.hpp>
#include <boost/beast/core/detail/tuple.hpp> #include <boost/beast/core/detail/tuple.hpp>
#include <boost/asio/associated_allocator.hpp> #include <boost/asio/associator.hpp>
#include <boost/asio/associated_cancellation_slot.hpp>
#include <boost/asio/associated_executor.hpp>
#include <boost/asio/handler_continuation_hook.hpp> #include <boost/asio/handler_continuation_hook.hpp>
#include <boost/core/ignore_unused.hpp> #include <boost/core/ignore_unused.hpp>
#include <boost/mp11/integer_sequence.hpp> #include <boost/mp11/integer_sequence.hpp>
@@ -42,14 +40,9 @@ class bind_wrapper
Handler h_; Handler h_;
args_type args_; args_type args_;
template<class T, class Executor> template <template <typename, typename> class Associator,
friend struct net::associated_executor; typename T, typename DefaultCandidate>
friend struct net::associator;
template<class T, class Allocator>
friend struct net::associated_allocator;
template<class T, class CancellationSlot>
friend struct net::associated_cancellation_slot;
template<class Arg, class Vals> template<class Arg, class Vals>
static static
@@ -186,15 +179,9 @@ class bind_front_wrapper
Handler h_; Handler h_;
detail::tuple<Args...> args_; detail::tuple<Args...> args_;
template<class T, class Executor> template <template <typename, typename> class Associator,
friend struct net::associated_executor; typename T, typename DefaultCandidate>
friend struct net::associator;
template<class T, class Allocator>
friend struct net::associated_allocator;
template<class T, class CancellationSlot>
friend struct net::associated_cancellation_slot;
template<std::size_t... I, class... Ts> template<std::size_t... I, class... Ts>
void void
@@ -264,112 +251,46 @@ public:
namespace boost { namespace boost {
namespace asio { namespace asio {
template<class Handler, class... Args, class Executor> template <template <typename, typename> class Associator,
struct associated_executor< typename Handler, typename... Args, typename DefaultCandidate>
beast::detail::bind_wrapper<Handler, Args...>, Executor> struct associator<Associator,
beast::detail::bind_wrapper<Handler, Args...>, DefaultCandidate>
: Associator<Handler, DefaultCandidate>
{ {
using type = typename static typename Associator<Handler, DefaultCandidate>::type get(
associated_executor<Handler, Executor>::type; const beast::detail::bind_wrapper<Handler, Args...>& h) noexcept
static
type
get(beast::detail::bind_wrapper<Handler, Args...> const& op,
Executor const& ex = Executor{}) noexcept
{ {
return associated_executor< return Associator<Handler, DefaultCandidate>::get(h.h_);
Handler, Executor>::get(op.h_, ex); }
static auto get(const beast::detail::bind_wrapper<Handler, Args...>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<Handler, DefaultCandidate>::get(h.h_, c))
{
return Associator<Handler, DefaultCandidate>::get(h.h_, c);
} }
}; };
template<class Handler, class... Args, class Executor> template <template <typename, typename> class Associator,
struct associated_executor< typename Handler, typename... Args, typename DefaultCandidate>
beast::detail::bind_front_wrapper<Handler, Args...>, Executor> struct associator<Associator,
beast::detail::bind_front_wrapper<Handler, Args...>, DefaultCandidate>
: Associator<Handler, DefaultCandidate>
{ {
using type = typename static typename Associator<Handler, DefaultCandidate>::type get(
associated_executor<Handler, Executor>::type; const beast::detail::bind_front_wrapper<Handler, Args...>& h) noexcept
static
type
get(beast::detail::bind_front_wrapper<Handler, Args...> const& op,
Executor const& ex = Executor{}) noexcept
{ {
return associated_executor< return Associator<Handler, DefaultCandidate>::get(h.h_);
Handler, Executor>::get(op.h_, ex); }
static auto get(const beast::detail::bind_front_wrapper<Handler, Args...>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<Handler, DefaultCandidate>::get(h.h_, c))
{
return Associator<Handler, DefaultCandidate>::get(h.h_, c);
} }
}; };
//
template<class Handler, class... Args, class Allocator>
struct associated_allocator<
beast::detail::bind_wrapper<Handler, Args...>, Allocator>
{
using type = typename
associated_allocator<Handler, Allocator>::type;
static
type
get(beast::detail::bind_wrapper<Handler, Args...> const& op,
Allocator const& alloc = Allocator{}) noexcept
{
return associated_allocator<
Handler, Allocator>::get(op.h_, alloc);
}
};
template<class Handler, class... Args, class Allocator>
struct associated_allocator<
beast::detail::bind_front_wrapper<Handler, Args...>, Allocator>
{
using type = typename
associated_allocator<Handler, Allocator>::type;
static
type
get(beast::detail::bind_front_wrapper<Handler, Args...> const& op,
Allocator const& alloc = Allocator{}) noexcept
{
return associated_allocator<
Handler, Allocator>::get(op.h_, alloc);
}
};
template<class Handler, class... Args, class CancellationSlot>
struct associated_cancellation_slot<
beast::detail::bind_wrapper<Handler, Args...>, CancellationSlot>
{
using type = typename
associated_cancellation_slot<Handler>::type;
static
type
get(beast::detail::bind_wrapper<Handler, Args...> const& op,
CancellationSlot const& slot = CancellationSlot{}) noexcept
{
return associated_cancellation_slot<
Handler, CancellationSlot>::get(op.h_, slot);
}
};
template<class Handler, class... Args, class CancellationSlot>
struct associated_cancellation_slot<
beast::detail::bind_front_wrapper<Handler, Args...>, CancellationSlot>
{
using type = typename
associated_cancellation_slot<Handler>::type;
static
type
get(beast::detail::bind_front_wrapper<Handler, Args...> const& op,
CancellationSlot const& slot = CancellationSlot{}) noexcept
{
return associated_cancellation_slot<
Handler, CancellationSlot>::get(op.h_, slot);
}
};
} // asio } // asio
} // boost } // boost

View File

@@ -775,7 +775,7 @@ public:
BEAST_EXPECT(ioc.run() == 0); BEAST_EXPECT(ioc.run() == 0);
BEAST_EXPECT(count == 3); BEAST_EXPECT(count == 3);
BEAST_EXPECT(ic == 6); BEAST_EXPECT(ic == 3);
}); });
} }