Skip to content

Commit

Permalink
fix #150
Browse files Browse the repository at this point in the history
Signed-off-by: Rafael Silva <[email protected]>
  • Loading branch information
perigoso committed May 24, 2022
1 parent 08fff71 commit c589ff4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/mqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ struct mqtt_fixed_header {
MQTT_ERROR(MQTT_ERROR_INITIAL_RECONNECT) \
MQTT_ERROR(MQTT_ERROR_INVALID_REMAINING_LENGTH) \
MQTT_ERROR(MQTT_ERROR_CLEAN_SESSION_IS_REQUIRED) \
MQTT_ERROR(MQTT_ERROR_RECONNECT_FAILED) \
MQTT_ERROR(MQTT_ERROR_RECONNECTING)

/* todo: add more connection refused errors */
Expand Down
10 changes: 9 additions & 1 deletion src/mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,15 @@ enum MQTTErrors mqtt_sync(struct mqtt_client *client) {
MQTT_PAL_MUTEX_LOCK(&client->mutex);
if (client->error != MQTT_ERROR_RECONNECTING && client->error != MQTT_OK && client->user_callback != NULL) {
client->user_callback(client, MQTT_EVENT_RECONNECT, NULL, &client->user_callback_state);
/* unlocked during CONNECT */
if (client->error != MQTT_OK) {
client->error = MQTT_ERROR_RECONNECT_FAILED;

/* normally unlocked during CONNECT */
MQTT_PAL_MUTEX_UNLOCK(&client->mutex);
}

err = client->error;
if (err != MQTT_OK) goto ERR;
} else {
/* mqtt_reconnect will have queued the disconnect packet - that needs to be sent and then call reconnect */
if (client->error == MQTT_ERROR_RECONNECTING) {
Expand Down

0 comments on commit c589ff4

Please sign in to comment.