Skip to content

Commit

Permalink
Do not call disconnect callback for "continue". Allow unsubscribe aft…
Browse files Browse the repository at this point in the history
…er "exit" in multi-threaded example.
  • Loading branch information
dgarske committed Nov 8, 2023
1 parent efde83c commit dd75c2f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 4 additions & 3 deletions examples/multithread/multithread.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,14 @@ static int mqtt_stop_get(void)
return rc;
}

#define MQTT_CODE_TEST_EXIT -200
static int check_response(MQTTCtx* mqttCtx, int rc, word32* startSec,
int packet_type, word32 timeoutMs)
{
/* check for test mode */
if (mqtt_stop_get()) {
if (mqtt_stop_get() && packet_type != MQTT_PACKET_TYPE_UNSUBSCRIBE) {
PRINTF("MQTT Exiting Thread...");
return MQTT_CODE_ERROR_SYSTEM;
return MQTT_CODE_TEST_EXIT;
}

#ifdef WOLFMQTT_NONBLOCK
Expand Down Expand Up @@ -387,7 +388,7 @@ static int multithread_test_finish(MQTTCtx *mqttCtx)

PRINTF("MQTT Client Done: %d", mqttCtx->return_code);

if (mStopRead && mqttCtx->return_code == MQTT_CODE_ERROR_SYSTEM) {
if (mStopRead && mqttCtx->return_code == MQTT_CODE_TEST_EXIT) {
/* this is okay, we requested termination */
mqttCtx->return_code = MQTT_CODE_SUCCESS;
}
Expand Down
7 changes: 6 additions & 1 deletion src/mqtt_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -2466,8 +2466,13 @@ int MqttClient_Disconnect_ex(MqttClient *client, MqttDisconnect *p_disconnect)

#if defined(WOLFMQTT_DISCONNECT_CB) && defined(WOLFMQTT_USE_CB_ON_DISCONNECT)
/* Trigger disconnect callback */
if (client->disconnect_cb)
if (client->disconnect_cb
#ifdef WOLFMQTT_NONBLOCK
&& rc != MQTT_CODE_CONTINUE
#endif
) {
client->disconnect_cb(client, rc, client->disconnect_ctx);
}
#endif

/* No response for MQTT disconnect packet */
Expand Down

0 comments on commit dd75c2f

Please sign in to comment.