mirror of
https://github.com/espressif/esp-mqtt.git
synced 2025-11-15 14:59:38 +01:00
Merge branch 'feature/outbox_limit' into 'master'
MQTT: Cleanup expired messages when offline See merge request espressif/esp-mqtt!76
This commit is contained in:
@@ -1333,6 +1333,14 @@ static void esp_mqtt_task(void *pv)
|
||||
break;
|
||||
}
|
||||
|
||||
//Delete message after OUTBOX_EXPIRED_TIMEOUT_MS miliseconds
|
||||
int deleted = outbox_delete_expired(client->outbox, platform_tick_get_ms(), OUTBOX_EXPIRED_TIMEOUT_MS);
|
||||
client->mqtt_state.pending_msg_count -= deleted;
|
||||
|
||||
if (client->mqtt_state.pending_msg_count < 0) {
|
||||
client->mqtt_state.pending_msg_count = 0;
|
||||
}
|
||||
|
||||
// resend all non-transmitted messages first
|
||||
outbox_item_handle_t item = outbox_dequeue(client->outbox, QUEUED, NULL);
|
||||
if (item) {
|
||||
@@ -1373,13 +1381,6 @@ static void esp_mqtt_task(void *pv)
|
||||
client->state = MQTT_STATE_INIT;
|
||||
}
|
||||
|
||||
//Delete message after 30 seconds
|
||||
int deleted = outbox_delete_expired(client->outbox, platform_tick_get_ms(), OUTBOX_EXPIRED_TIMEOUT_MS);
|
||||
client->mqtt_state.pending_msg_count -= deleted;
|
||||
if (client->mqtt_state.pending_msg_count < 0) {
|
||||
client->mqtt_state.pending_msg_count = 0;
|
||||
}
|
||||
//
|
||||
outbox_cleanup(client->outbox, OUTBOX_MAX_SIZE);
|
||||
break;
|
||||
case MQTT_STATE_WAIT_TIMEOUT:
|
||||
@@ -1630,6 +1631,18 @@ int esp_mqtt_client_publish(esp_mqtt_client_handle_t client, const char *topic,
|
||||
/* Skip sending if not connected (rely on resending) */
|
||||
if (client->state != MQTT_STATE_CONNECTED) {
|
||||
ESP_LOGD(TAG, "Publish: client is not connected");
|
||||
if (qos > 0) {
|
||||
ret = pending_msg_id;
|
||||
}
|
||||
|
||||
//Delete message after OUTBOX_EXPIRED_TIMEOUT_MS miliseconds
|
||||
int deleted = outbox_delete_expired(client->outbox, platform_tick_get_ms(), OUTBOX_EXPIRED_TIMEOUT_MS);
|
||||
client->mqtt_state.pending_msg_count -= deleted;
|
||||
|
||||
if (client->mqtt_state.pending_msg_count < 0) {
|
||||
client->mqtt_state.pending_msg_count = 0;
|
||||
}
|
||||
|
||||
goto cannot_publish;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user