Add function to set keep alive/ping interval

Summary:
related to T13566
- mqtt_client has a new keep_alive(seconds) function
- keep_alive(0) disables ping
- if keep_alive() is not called, the client assumes keep_alive=10
- the client respects server_keep_alive if sent by the broker

Reviewers: ivica

Reviewed By: ivica

Subscribers: miljen, iljazovic

Differential Revision: https://repo.mireo.local/D27557
This commit is contained in:
Korina Šimičević committed 2024-02-01 08:29:22 +01:00
1 parent d6c4884d53
commit 33c8eea890
21 files changed
+361 -100

No files matched your search

+5 -1
View File
@@ -246,10 +246,14 @@ public:
asio::dispatch(asio::prepend(std::move(handler), ec, bytes));
}
void cancel_pending_read() {
_pending_read.complete(get_executor(), asio::error::operation_aborted, 0);
}
private:
void shutdown() override {
_pending_read.complete(get_executor(), asio::error::operation_aborted, 0);
cancel_pending_read();
}
void launch_broker_ops() {
+17 -11
View File
@@ -9,6 +9,8 @@
#include <boost/asio/ip/tcp.hpp>
#include <async_mqtt5/detail/cancellable_handler.hpp>
#include "test_common/test_broker.hpp"
namespace async_mqtt5::test {
@@ -94,15 +96,25 @@ template <typename Handler>
class read_op {
struct on_read {};
std::shared_ptr<test_stream_impl> _stream_impl;
Handler _handler;
using handler_type = async_mqtt5::detail::cancellable_handler<
Handler,
typename test_stream_impl::executor_type
>;
handler_type _handler;
public:
read_op(
std::shared_ptr<test_stream_impl> stream_impl, Handler handler
) :
_stream_impl(std::move(stream_impl)),
_handler(std::move(handler))
{}
_handler(std::move(handler), _stream_impl->get_executor())
{
auto slot = asio::get_associated_cancellation_slot(_handler);
if (slot.is_connected())
slot.assign([stream_impl = _stream_impl](asio::cancellation_type_t) {
stream_impl->_test_broker->cancel_pending_read();
});
}
read_op(read_op&&) noexcept = default;
read_op(const read_op&) = delete;
@@ -136,17 +148,11 @@ public:
private:
void complete_post(error_code ec, size_t bytes_read) {
asio::post(
get_executor(),
asio::prepend(std::move(_handler), ec, bytes_read)
);
_handler.complete_post(ec, bytes_read);
}
void complete(error_code ec, size_t bytes_read) {
asio::dispatch(
get_executor(),
asio::prepend(std::move(_handler), ec, bytes_read)
);
_handler.complete(ec, bytes_read);
}
};