mirror of
https://github.com/boostorg/mqtt5.git
synced 2025-11-08 11:51:41 +01:00
Initiation lambdas replaced with classes with executor_type/get_executor
Summary: related to #13, T13767 `asio::cancel_at` and `asio::cancel_after` (coming with Boost 1.86) use associated executor from the initiation object to construct the underlying timer. Therefore, initiation lambdas are replaced with classes with executor_type/get_executor to allow that functionality (like Asio/Beast). Alternative solutions: 1) asio::bind_executor(get_executor(), initiation) 2) async_compose Reviewers: ivica Reviewed By: ivica Subscribers: iljazovic, miljen Differential Revision: https://repo.mireo.local/D30861
This commit is contained in:
@@ -18,10 +18,9 @@
|
||||
|
||||
#include <async_mqtt5/impl/client_service.hpp>
|
||||
#include <async_mqtt5/impl/publish_send_op.hpp>
|
||||
#include <async_mqtt5/impl/read_message_op.hpp>
|
||||
#include <async_mqtt5/impl/re_auth_op.hpp>
|
||||
#include <async_mqtt5/impl/subscribe_op.hpp>
|
||||
#include <async_mqtt5/impl/unsubscribe_op.hpp>
|
||||
#include <async_mqtt5/impl/re_auth_op.hpp>
|
||||
|
||||
namespace async_mqtt5 {
|
||||
|
||||
@@ -202,18 +201,8 @@ public:
|
||||
>
|
||||
decltype(auto) async_run(CompletionToken&& token = {}) {
|
||||
using Signature = void (error_code);
|
||||
|
||||
auto initiation = [] (auto handler, const impl_type& impl) {
|
||||
auto ex = asio::get_associated_executor(handler, impl->get_executor());
|
||||
|
||||
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>(
|
||||
initiation, token, _impl
|
||||
detail::initiate_async_run(_impl), token
|
||||
);
|
||||
}
|
||||
|
||||
@@ -511,24 +500,10 @@ public:
|
||||
CompletionToken&& token = {}
|
||||
) {
|
||||
using Signature = detail::on_publish_signature<qos_type>;
|
||||
|
||||
auto initiation = [] (
|
||||
auto handler, std::string topic, std::string payload,
|
||||
retain_e retain, const publish_props& props,
|
||||
const impl_type& impl
|
||||
) {
|
||||
detail::publish_send_op<
|
||||
client_service_type, decltype(handler), qos_type
|
||||
> { impl, std::move(handler) }
|
||||
.perform(
|
||||
std::move(topic), std::move(payload),
|
||||
retain, props
|
||||
);
|
||||
};
|
||||
|
||||
return asio::async_initiate<CompletionToken, Signature>(
|
||||
initiation, token,
|
||||
std::move(topic), std::move(payload), retain, props, _impl
|
||||
detail::initiate_async_publish<client_service_type, qos_type>(_impl),
|
||||
token,
|
||||
std::move(topic), std::move(payload), retain, props
|
||||
);
|
||||
}
|
||||
|
||||
@@ -599,17 +574,9 @@ public:
|
||||
using Signature = void (
|
||||
error_code, std::vector<reason_code>, suback_props
|
||||
);
|
||||
|
||||
auto initiation = [] (
|
||||
auto handler, const std::vector<subscribe_topic>& topics,
|
||||
const subscribe_props& props, const impl_type& impl
|
||||
) {
|
||||
detail::subscribe_op { impl, std::move(handler) }
|
||||
.perform(topics, props);
|
||||
};
|
||||
|
||||
return asio::async_initiate<CompletionToken, Signature>(
|
||||
initiation, token, topics, props, _impl
|
||||
detail::initiate_async_subscribe(_impl), token,
|
||||
topics, props
|
||||
);
|
||||
}
|
||||
|
||||
@@ -745,18 +712,9 @@ public:
|
||||
using Signature = void (
|
||||
error_code, std::vector<reason_code>, unsuback_props
|
||||
);
|
||||
|
||||
auto initiation = [](
|
||||
auto handler,
|
||||
const std::vector<std::string>& topics,
|
||||
const unsubscribe_props& props, const impl_type& impl
|
||||
) {
|
||||
detail::unsubscribe_op { impl, std::move(handler) }
|
||||
.perform(topics, props);
|
||||
};
|
||||
|
||||
return asio::async_initiate<CompletionToken, Signature>(
|
||||
initiation, token, topics, props, _impl
|
||||
detail::initiate_async_unsubscribe(_impl), token,
|
||||
topics, props
|
||||
);
|
||||
}
|
||||
|
||||
@@ -879,10 +837,7 @@ public:
|
||||
typename asio::default_completion_token<executor_type>::type
|
||||
>
|
||||
decltype(auto) async_receive(CompletionToken&& token = {}) {
|
||||
// Sig = void (error_code, std::string, std::string, publish_props)
|
||||
return _impl->async_channel_receive(
|
||||
std::forward<CompletionToken>(token)
|
||||
);
|
||||
return _impl->async_channel_receive(std::forward<CompletionToken>(token));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1008,6 +963,7 @@ public:
|
||||
disconnect_props {}, std::forward<CompletionToken>(token)
|
||||
);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user