Fix early retransmit

The time for retransmitting a message was set before transfer was done. This ment that if the transfer speed is slow or the message is big then it would be possible to trigger a retransmit too early.

Closes https://github.com/espressif/esp-mqtt/issues/131
This commit is contained in:
Marius Vikhammer
2019-09-30 14:57:24 +08:00
committed by David Cermak
parent 40302a3d43
commit 52cdfa9087
3 changed files with 14 additions and 1 deletions

View File

@@ -45,6 +45,7 @@ esp_err_t outbox_delete_msgtype(outbox_handle_t outbox, int msg_type);
int outbox_delete_expired(outbox_handle_t outbox, int current_tick, int timeout);
esp_err_t outbox_set_pending(outbox_handle_t outbox, int msg_id, pending_state_t pending);
esp_err_t outbox_set_tick(outbox_handle_t outbox, int msg_id, int tick);
int outbox_get_size(outbox_handle_t outbox);
esp_err_t outbox_cleanup(outbox_handle_t outbox, int max_size);
void outbox_destroy(outbox_handle_t outbox);

View File

@@ -131,6 +131,16 @@ esp_err_t outbox_set_pending(outbox_handle_t outbox, int msg_id, pending_state_t
return ESP_FAIL;
}
esp_err_t outbox_set_tick(outbox_handle_t outbox, int msg_id, int tick)
{
outbox_item_handle_t item = outbox_get(outbox, msg_id);
if (item) {
item->tick = tick;
return ESP_OK;
}
return ESP_FAIL;
}
esp_err_t outbox_delete_msgtype(outbox_handle_t outbox, int msg_type)
{
outbox_item_handle_t item, tmp;

View File

@@ -1355,7 +1355,9 @@ int esp_mqtt_client_publish(esp_mqtt_client_handle_t client, const char *topic,
}
}
if (qos > 0) {
if (qos > 0) {
//Tick is set after transmit to avoid retransmitting too early due slow network speed / big messages
outbox_set_tick(client->outbox, pending_msg_id, platform_tick_get_ms());
outbox_set_pending(client->outbox, pending_msg_id, TRANSMITTED);
}
MQTT_API_UNLOCK_FROM_OTHER_TASK(client);