Giter Site home page Giter Site logo

Comments (4)

redboltz avatar redboltz commented on July 30, 2024

You can know MQTT level status as follows:

First, call recv(), then you can get packet_variant as the CompletionToken of the recv().

using variant_t = variant<
system_error,
v3_1_1::connect_packet,
v3_1_1::connack_packet,
v3_1_1::basic_publish_packet<PacketIdBytes>,
v3_1_1::basic_puback_packet<PacketIdBytes>,
v3_1_1::basic_pubrec_packet<PacketIdBytes>,
v3_1_1::basic_pubrel_packet<PacketIdBytes>,
v3_1_1::basic_pubcomp_packet<PacketIdBytes>,
v3_1_1::basic_subscribe_packet<PacketIdBytes>,
v3_1_1::basic_suback_packet<PacketIdBytes>,
v3_1_1::basic_unsubscribe_packet<PacketIdBytes>,
v3_1_1::basic_unsuback_packet<PacketIdBytes>,
v3_1_1::pingreq_packet,
v3_1_1::pingresp_packet,
v3_1_1::disconnect_packet,
v5::connect_packet,
v5::connack_packet,
v5::basic_publish_packet<PacketIdBytes>,
v5::basic_puback_packet<PacketIdBytes>,
v5::basic_pubrec_packet<PacketIdBytes>,
v5::basic_pubrel_packet<PacketIdBytes>,
v5::basic_pubcomp_packet<PacketIdBytes>,
v5::basic_subscribe_packet<PacketIdBytes>,
v5::basic_suback_packet<PacketIdBytes>,
v5::basic_unsubscribe_packet<PacketIdBytes>,
v5::basic_unsuback_packet<PacketIdBytes>,
v5::pingreq_packet,
v5::pingresp_packet,
v5::disconnect_packet,
v5::auth_packet
>;

The index 0 of the packet_variant is system_error.
If connection is lost, then the system_error is set.

For convinience, packet_variant has operator bool().

operator bool() {
return var_.index() != 0;
}

If you want to know the reason of connection lost, you can get system_error from the packet_variant, then call .what() function.

from async_mqtt.

magni-mar avatar magni-mar commented on July 30, 2024

My problem is that I want to check weather the connection is open while I am actively receiving in another place in the program. This causes me to not be able to initiate another receive.

from async_mqtt.

redboltz avatar redboltz commented on July 30, 2024

You can store the result of recv() in your application as a flag.

I guess that you would expect something like bool endpoint::connected(). But there is no such function because it is not a good idea.

async_mqtt doesn't own io_context. Just refer it.
So how to call io_context::run() is client's responsibility. It could call from different thread or multiple threads.

In this case the return valur of connected() is unreliable.

if (ep.connected()) {
    // could have already been disconnected here
}

When the status flag is reliable ? Only application developper knows it.
So it should be implemented by application side, not in the library.

from async_mqtt.

magni-mar avatar magni-mar commented on July 30, 2024

I understand, thanks for the response.

from async_mqtt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.