Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can MQTTClient_receive return MQTTv5 error code #1529

Open
cuttlfish opened this issue Oct 2, 2024 · 0 comments
Open

Can MQTTClient_receive return MQTTv5 error code #1529

cuttlfish opened this issue Oct 2, 2024 · 0 comments

Comments

@cuttlfish
Copy link

cuttlfish commented Oct 2, 2024

Is your feature request related to a problem? Please describe.
Currently using MQTTClient API, and only way to get MQTTv5 error code is to set disconnect callback which then also requires messageArrived callback to be set which internally spins a thread and kind of defeats the purpose for synchronous API

Describe the solution you'd like
Since my thread is calling MQTTClient_receive already, it be nice it that function can return the exact error code of a disconnect

Describe alternatives you've considered
I tried something like this and it seems to work

 @@ -2798,7 +2800,16 @@ int MQTTClient_receive(MQTTClient handle, char** topicName, int* topicLen, MQTTC
         do
        {
                SOCKET sock = 0;
 -               MQTTClient_cycle(&sock, (timeout > elapsed) ? timeout - elapsed : 0L, &rc);
 +              MQTTPacket* pack = NULL;
 +               pack = MQTTClient_cycle(&sock, (timeout > elapsed) ? timeout - elapsed : 0L, &rc);
 +              if (pack) {
 +                  if (m->c->MQTTVersion >= MQTTVERSION_5)
 +                  if (pack->header.bits.type == DISCONNECT && m->disconnected) {
 +                    Ack* disc = (Ack*)pack;
 +                    rc = disc->rc;
 +                    goto exit;
 +                }
 +        }
 
                 if (rc == SOCKET_ERROR)
                 {

Additional context
Add any other context or screenshots about the feature request here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant