mirror of
https://github.com/boostorg/mqtt5.git
synced 2025-11-09 04:11:36 +01:00
async_run's associated ex will not replace mqtt_client's default ex
Summary: related to T13767 Reviewers: ivica Reviewed By: ivica Subscribers: miljen, iljazovic Differential Revision: https://repo.mireo.local/D29383
This commit is contained in:
@@ -223,10 +223,10 @@ private:
|
||||
template <typename ClientService, typename Handler>
|
||||
friend class assemble_op;
|
||||
|
||||
template <typename ClientService>
|
||||
template <typename ClientService, typename Executor>
|
||||
friend class ping_op;
|
||||
|
||||
template <typename ClientService>
|
||||
template <typename ClientService, typename Executor>
|
||||
friend class sentry_op;
|
||||
|
||||
template <typename ClientService>
|
||||
@@ -369,7 +369,6 @@ public:
|
||||
|
||||
template <typename Handler>
|
||||
void run(Handler&& handler) {
|
||||
_executor = asio::get_associated_executor(handler, _executor);
|
||||
_run_handler = std::move(handler);
|
||||
auto slot = asio::get_associated_cancellation_slot(_run_handler);
|
||||
if (slot.is_connected()) {
|
||||
|
||||
@@ -20,20 +20,28 @@ namespace async_mqtt5::detail {
|
||||
|
||||
namespace asio = boost::asio;
|
||||
|
||||
template <typename ClientService>
|
||||
template <typename ClientService, typename Executor>
|
||||
class ping_op {
|
||||
public:
|
||||
using executor_type = Executor;
|
||||
private:
|
||||
using client_service = ClientService;
|
||||
|
||||
struct on_timer {};
|
||||
struct on_pingreq {};
|
||||
|
||||
std::shared_ptr<client_service> _svc_ptr;
|
||||
executor_type _executor;
|
||||
std::unique_ptr<asio::steady_timer> _ping_timer;
|
||||
asio::cancellation_state _cancellation_state;
|
||||
|
||||
public:
|
||||
ping_op(const std::shared_ptr<client_service>& svc_ptr) :
|
||||
_svc_ptr(svc_ptr),
|
||||
_ping_timer(new asio::steady_timer(svc_ptr->get_executor())),
|
||||
ping_op(
|
||||
const std::shared_ptr<client_service>& svc_ptr,
|
||||
const executor_type& ex
|
||||
) :
|
||||
_svc_ptr(svc_ptr), _executor(ex),
|
||||
_ping_timer(new asio::steady_timer(_svc_ptr->get_executor())),
|
||||
_cancellation_state(
|
||||
svc_ptr->_cancel_ping.slot(),
|
||||
asio::enable_total_cancellation {},
|
||||
@@ -44,9 +52,8 @@ public:
|
||||
ping_op(ping_op&&) noexcept = default;
|
||||
ping_op(const ping_op&) = delete;
|
||||
|
||||
using executor_type = typename client_service::executor_type;
|
||||
executor_type get_executor() const noexcept {
|
||||
return _svc_ptr->get_executor();
|
||||
return _executor;
|
||||
}
|
||||
|
||||
using allocator_type = asio::recycling_allocator<void>;
|
||||
|
||||
@@ -20,26 +20,31 @@ namespace async_mqtt5::detail {
|
||||
|
||||
namespace asio = boost::asio;
|
||||
|
||||
template <typename ClientService>
|
||||
template <typename ClientService, typename Executor>
|
||||
class read_message_op {
|
||||
public:
|
||||
using executor_type = Executor;
|
||||
private:
|
||||
using client_service = ClientService;
|
||||
|
||||
struct on_message {};
|
||||
struct on_disconnect {};
|
||||
|
||||
std::shared_ptr<client_service> _svc_ptr;
|
||||
executor_type _executor;
|
||||
public:
|
||||
read_message_op(
|
||||
const std::shared_ptr<client_service>& svc_ptr
|
||||
const std::shared_ptr<client_service>& svc_ptr,
|
||||
const executor_type& ex
|
||||
) :
|
||||
_svc_ptr(svc_ptr)
|
||||
_svc_ptr(svc_ptr), _executor(ex)
|
||||
{}
|
||||
|
||||
read_message_op(read_message_op&&) noexcept = default;
|
||||
read_message_op(const read_message_op&) = delete;
|
||||
|
||||
using executor_type = typename client_service::executor_type;
|
||||
executor_type get_executor() const noexcept {
|
||||
return _svc_ptr->get_executor();
|
||||
return _executor;
|
||||
}
|
||||
|
||||
using allocator_type = asio::recycling_allocator<void>;
|
||||
|
||||
@@ -16,31 +16,36 @@ namespace async_mqtt5::detail {
|
||||
|
||||
namespace asio = boost::asio;
|
||||
|
||||
template <typename ClientService>
|
||||
template <typename ClientService, typename Executor>
|
||||
class sentry_op {
|
||||
public:
|
||||
using executor_type = Executor;
|
||||
private:
|
||||
using client_service = ClientService;
|
||||
|
||||
struct on_timer {};
|
||||
struct on_disconnect {};
|
||||
|
||||
static constexpr auto check_interval = std::chrono::seconds(3);
|
||||
|
||||
std::shared_ptr<client_service> _svc_ptr;
|
||||
executor_type _executor;
|
||||
std::unique_ptr<asio::steady_timer> _sentry_timer;
|
||||
|
||||
public:
|
||||
sentry_op(
|
||||
const std::shared_ptr<client_service>& svc_ptr
|
||||
const std::shared_ptr<client_service>& svc_ptr,
|
||||
const executor_type& ex
|
||||
) :
|
||||
_svc_ptr(svc_ptr),
|
||||
_sentry_timer(new asio::steady_timer(svc_ptr->get_executor()))
|
||||
_svc_ptr(svc_ptr), _executor(ex),
|
||||
_sentry_timer(new asio::steady_timer(_svc_ptr->get_executor()))
|
||||
{}
|
||||
|
||||
sentry_op(sentry_op&&) noexcept = default;
|
||||
sentry_op(const sentry_op&) = delete;
|
||||
|
||||
using executor_type = typename client_service::executor_type;
|
||||
executor_type get_executor() const noexcept {
|
||||
return _svc_ptr->get_executor();
|
||||
return _executor;
|
||||
}
|
||||
|
||||
using allocator_type = asio::recycling_allocator<void>;
|
||||
|
||||
@@ -180,11 +180,12 @@ public:
|
||||
using Signature = void(error_code);
|
||||
|
||||
auto initiation = [] (auto handler, const impl_type& impl) {
|
||||
impl->run(std::move(handler));
|
||||
auto ex = asio::get_associated_executor(handler, impl->get_executor());
|
||||
|
||||
detail::ping_op { impl }.perform();
|
||||
detail::read_message_op { impl }.perform();
|
||||
detail::sentry_op { impl }.perform();
|
||||
impl->run(std::move(handler));
|
||||
detail::ping_op { impl, ex }.perform();
|
||||
detail::read_message_op { impl, ex }.perform();
|
||||
detail::sentry_op { impl, ex }.perform();
|
||||
};
|
||||
|
||||
return asio::async_initiate<CompletionToken, Signature>(
|
||||
|
||||
Reference in New Issue
Block a user