mqtt5: Fix flow control will increase count when send fragmented packet

Closes https://github.com/espressif/esp-mqtt/issues/255
This commit is contained in:
yuanjianmin
2023-03-17 16:55:25 +08:00
parent 9f2db7b4b6
commit 5cce2c4f35
2 changed files with 18 additions and 11 deletions

View File

@ -19,8 +19,7 @@ static esp_err_t esp_mqtt5_user_property_copy(mqtt5_user_property_handle_t user_
void esp_mqtt5_increment_packet_counter(esp_mqtt5_client_handle_t client)
{
bool msg_dup = mqtt5_get_dup(client->mqtt_state.outbound_message->data);
int msg_qos = mqtt5_get_qos(client->mqtt_state.outbound_message->data);
if ((msg_dup == false) && (msg_qos > 0)) {
if (msg_dup == false) {
client->send_publish_packet_count ++;
ESP_LOGD(TAG, "Sent (%d) qos > 0 publish packet without ack", client->send_publish_packet_count);
}

View File

@ -943,11 +943,6 @@ static esp_err_t mqtt_write_data(esp_mqtt_client_handle_t client)
esp_mqtt_client_dispatch_transport_error(client);
return ESP_FAIL;
}
#ifdef MQTT_PROTOCOL_5
if (client->connect_info.protocol_ver == MQTT_PROTOCOL_V_5) {
esp_mqtt5_increment_packet_counter(client);
}
#endif
return ESP_OK;
}
@ -1475,10 +1470,18 @@ static esp_err_t mqtt_resend_queued(esp_mqtt_client_handle_t client, outbox_item
}
// check if it was QoS-0 publish message
if (client->mqtt_state.pending_msg_type == MQTT_MSG_TYPE_PUBLISH && client->mqtt_state.pending_publish_qos == 0) {
// delete all qos0 publish messages once we process them
if (outbox_delete_item(client->outbox, item) != ESP_OK) {
ESP_LOGE(TAG, "Failed to remove queued qos0 message from the outbox");
if (client->mqtt_state.pending_msg_type == MQTT_MSG_TYPE_PUBLISH) {
if (client->mqtt_state.pending_publish_qos == 0) {
// delete all qos0 publish messages once we process them
if (outbox_delete_item(client->outbox, item) != ESP_OK) {
ESP_LOGE(TAG, "Failed to remove queued qos0 message from the outbox");
}
} else if (client->mqtt_state.pending_publish_qos > 0) {
#ifdef MQTT_PROTOCOL_5
if (client->connect_info.protocol_ver == MQTT_PROTOCOL_V_5) {
esp_mqtt5_increment_packet_counter(client);
}
#endif
}
}
return ESP_OK;
@ -2090,6 +2093,11 @@ int esp_mqtt_client_publish(esp_mqtt_client_handle_t client, const char *topic,
}
if (qos > 0) {
#ifdef MQTT_PROTOCOL_5
if (client->connect_info.protocol_ver == MQTT_PROTOCOL_V_5) {
esp_mqtt5_increment_packet_counter(client);
}
#endif
//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);