mireo / async-mqtt5

A C++17 MQTT client based on Boost.Asio.
https://spacetime.mireo.com/async-mqtt5/
Boost Software License 1.0
154 stars 11 forks source link

Problems with async_run()/async_disconnect() in a loop and does not compile with boost-1.84.0 #5

Closed lproj closed 9 months ago

lproj commented 9 months ago

Hi,

I have two separated problems with this library at the moment.

Thanks for your help!

#include <async_mqtt5.hpp>
#include <boost/asio/co_spawn.hpp>
#include <boost/asio/detached.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/use_awaitable.hpp>

asio::awaitable<void> client_receiver(asio::io_context& ioc) {
    async_mqtt5::mqtt_client<asio::ip::tcp::socket> client(ioc, "");

    client.brokers("localhost", 1883);

    for (int retry = 0; retry < 10; retry++) {
        client.async_run(asio::detached);

        async_mqtt5::subscribe_topic sub_topic = async_mqtt5::subscribe_topic{
            "test/mqtt-test", async_mqtt5::subscribe_options{
                                  async_mqtt5::qos_e::exactly_once, async_mqtt5::no_local_e::yes,
                                  async_mqtt5::retain_as_published_e::dont, async_mqtt5::retain_handling_e::not_send}};

        // Subscribe to a single Topic.
        auto [sub_codes, sub_props] =
            co_await client.async_subscribe(sub_topic, async_mqtt5::subscribe_props{}, asio::use_awaitable);

        // Disconnect the Client.
        co_await client.async_disconnect(async_mqtt5::disconnect_rc_e::normal_disconnection,
                                         async_mqtt5::disconnect_props{}, asio::use_awaitable);
    }

    co_return;
}

int main() {
    asio::io_context ioc;
    co_spawn(ioc, client_receiver(ioc), asio::detached);
    ioc.run();
}
ksimicevic commented 9 months ago

Hello!

Thank you very much for submitting this issue!

We have looked into it and were able to reproduce the issues you have described:

Thank you for your patience!

Cheers, Korina