diff --git a/examples/multithread/multithread.c b/examples/multithread/multithread.c index 91515d769..4114d4549 100755 --- a/examples/multithread/multithread.c +++ b/examples/multithread/multithread.c @@ -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 @@ -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; } diff --git a/src/mqtt_client.c b/src/mqtt_client.c index 0af4d05d5..fbd7044f1 100644 --- a/src/mqtt_client.c +++ b/src/mqtt_client.c @@ -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 */