Skip to content

Commit

Permalink
Change redirect_error to propagate an initiation object's executor.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskohlhoff committed Jun 25, 2024
1 parent 1d5a685 commit 966a24c
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions asio/include/asio/impl/redirect_error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "asio/associator.hpp"
#include "asio/async_result.hpp"
#include "asio/detail/handler_cont_helpers.hpp"
#include "asio/detail/initiation_base.hpp"
#include "asio/detail/type_traits.hpp"
#include "asio/system_error.hpp"

Expand Down Expand Up @@ -183,25 +184,30 @@ struct async_result<redirect_error_t<CompletionToken>, Signature>
: async_result<CompletionToken,
typename detail::redirect_error_signature<Signature>::type>
{

struct init_wrapper
template <typename Initiation>
struct init_wrapper : detail::initiation_base<Initiation>
{
explicit init_wrapper(asio::error_code& ec)
: ec_(ec)
using detail::initiation_base<Initiation>::initiation_base;

template <typename Handler, typename... Args>
void operator()(Handler&& handler,
asio::error_code* ec, Args&&... args) &&
{
static_cast<Initiation&&>(*this)(
detail::redirect_error_handler<decay_t<Handler>>(
*ec, static_cast<Handler&&>(handler)),
static_cast<Args&&>(args)...);
}

template <typename Handler, typename Initiation, typename... Args>
template <typename Handler, typename... Args>
void operator()(Handler&& handler,
Initiation&& initiation, Args&&... args) const
asio::error_code* ec, Args&&... args) const &
{
static_cast<Initiation&&>(initiation)(
static_cast<const Initiation&>(*this)(
detail::redirect_error_handler<decay_t<Handler>>(
ec_, static_cast<Handler&&>(handler)),
*ec, static_cast<Handler&&>(handler)),
static_cast<Args&&>(args)...);
}

asio::error_code& ec_;
};

template <typename Initiation, typename RawCompletionToken, typename... Args>
Expand All @@ -213,18 +219,17 @@ struct async_result<redirect_error_t<CompletionToken>, Signature>
is_const<remove_reference_t<RawCompletionToken>>::value,
const CompletionToken, CompletionToken>,
typename detail::redirect_error_signature<Signature>::type>(
declval<init_wrapper>(), token.token_,
static_cast<Initiation&&>(initiation),
static_cast<Args&&>(args)...))
declval<init_wrapper<decay_t<Initiation>>>(),
token.token_, &token.ec_, static_cast<Args&&>(args)...))
{
return async_initiate<
conditional_t<
is_const<remove_reference_t<RawCompletionToken>>::value,
const CompletionToken, CompletionToken>,
typename detail::redirect_error_signature<Signature>::type>(
init_wrapper(token.ec_), token.token_,
static_cast<Initiation&&>(initiation),
static_cast<Args&&>(args)...);
init_wrapper<decay_t<Initiation>>(
static_cast<Initiation&&>(initiation)),
token.token_, &token.ec_, static_cast<Args&&>(args)...);
}
};

Expand Down

0 comments on commit 966a24c

Please sign in to comment.