mirror of
https://github.com/espressif/esp-mqtt.git
synced 2025-07-30 18:58:07 +02:00
MQTT: add dispatch error event for read errors
Closes https://github.com/espressif/esp-idf/issues/5704
This commit is contained in:
@ -131,6 +131,8 @@ static esp_err_t esp_mqtt_abort_connection(esp_mqtt_client_handle_t client);
|
|||||||
static esp_err_t esp_mqtt_client_ping(esp_mqtt_client_handle_t client);
|
static esp_err_t esp_mqtt_client_ping(esp_mqtt_client_handle_t client);
|
||||||
static char *create_string(const char *ptr, int len);
|
static char *create_string(const char *ptr, int len);
|
||||||
static int mqtt_message_receive(esp_mqtt_client_handle_t client, int read_poll_timeout_ms);
|
static int mqtt_message_receive(esp_mqtt_client_handle_t client, int read_poll_timeout_ms);
|
||||||
|
static void esp_mqtt_client_dispatch_tls_error(esp_mqtt_client_handle_t client);
|
||||||
|
|
||||||
|
|
||||||
#if MQTT_ENABLE_SSL
|
#if MQTT_ENABLE_SSL
|
||||||
enum esp_mqtt_ssl_cert_key_api {
|
enum esp_mqtt_ssl_cert_key_api {
|
||||||
@ -847,15 +849,7 @@ static esp_err_t mqtt_write_data(esp_mqtt_client_handle_t client)
|
|||||||
client->config->network_timeout_ms);
|
client->config->network_timeout_ms);
|
||||||
// client->mqtt_state.pending_msg_type = mqtt_get_type(client->mqtt_state.outbound_message->data);
|
// client->mqtt_state.pending_msg_type = mqtt_get_type(client->mqtt_state.outbound_message->data);
|
||||||
if (write_len <= 0) {
|
if (write_len <= 0) {
|
||||||
client->event.event_id = MQTT_EVENT_ERROR;
|
esp_mqtt_client_dispatch_tls_error(client);
|
||||||
client->event.error_handle->error_type = MQTT_ERROR_TYPE_ESP_TLS;
|
|
||||||
client->event.error_handle->connect_return_code = 0;
|
|
||||||
#ifdef MQTT_SUPPORTED_FEATURE_TRANSPORT_ERR_REPORTING
|
|
||||||
client->event.error_handle->esp_tls_last_esp_err = esp_tls_get_and_clear_last_error(esp_transport_get_error_handle(client->transport),
|
|
||||||
&client->event.error_handle->esp_tls_stack_err,
|
|
||||||
&client->event.error_handle->esp_tls_cert_verify_flags);
|
|
||||||
#endif
|
|
||||||
esp_mqtt_dispatch_event_with_msgid(client);
|
|
||||||
ESP_LOGE(TAG, "Error write data or timeout, written len = %d, errno=%d", write_len, errno);
|
ESP_LOGE(TAG, "Error write data or timeout, written len = %d, errno=%d", write_len, errno);
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
@ -1131,6 +1125,7 @@ static int mqtt_message_receive(esp_mqtt_client_handle_t client, int read_poll_t
|
|||||||
ESP_LOGD(TAG, "%s: transport_read():%d %d", __func__, client->mqtt_state.in_buffer_read_len, client->mqtt_state.message_length);
|
ESP_LOGD(TAG, "%s: transport_read():%d %d", __func__, client->mqtt_state.in_buffer_read_len, client->mqtt_state.message_length);
|
||||||
return 1;
|
return 1;
|
||||||
err:
|
err:
|
||||||
|
esp_mqtt_client_dispatch_tls_error(client);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1307,15 +1302,7 @@ static void esp_mqtt_task(void *pv)
|
|||||||
client->config->port,
|
client->config->port,
|
||||||
client->config->network_timeout_ms) < 0) {
|
client->config->network_timeout_ms) < 0) {
|
||||||
ESP_LOGE(TAG, "Error transport connect");
|
ESP_LOGE(TAG, "Error transport connect");
|
||||||
client->event.event_id = MQTT_EVENT_ERROR;
|
esp_mqtt_client_dispatch_tls_error(client);
|
||||||
client->event.error_handle->error_type = MQTT_ERROR_TYPE_ESP_TLS;
|
|
||||||
client->event.error_handle->connect_return_code = 0;
|
|
||||||
#ifdef MQTT_SUPPORTED_FEATURE_TRANSPORT_ERR_REPORTING
|
|
||||||
client->event.error_handle->esp_tls_last_esp_err = esp_tls_get_and_clear_last_error(esp_transport_get_error_handle(client->transport),
|
|
||||||
&client->event.error_handle->esp_tls_stack_err,
|
|
||||||
&client->event.error_handle->esp_tls_cert_verify_flags);
|
|
||||||
#endif
|
|
||||||
esp_mqtt_dispatch_event_with_msgid(client);
|
|
||||||
esp_mqtt_abort_connection(client);
|
esp_mqtt_abort_connection(client);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1714,3 +1701,17 @@ esp_err_t esp_mqtt_client_register_event(esp_mqtt_client_handle_t client, esp_mq
|
|||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void esp_mqtt_client_dispatch_tls_error(esp_mqtt_client_handle_t client)
|
||||||
|
{
|
||||||
|
client->event.event_id = MQTT_EVENT_ERROR;
|
||||||
|
client->event.error_handle->error_type = MQTT_ERROR_TYPE_ESP_TLS;
|
||||||
|
client->event.error_handle->connect_return_code = 0;
|
||||||
|
#ifdef MQTT_SUPPORTED_FEATURE_TRANSPORT_ERR_REPORTING
|
||||||
|
client->event.error_handle->esp_tls_last_esp_err = esp_tls_get_and_clear_last_error(esp_transport_get_error_handle(client->transport),
|
||||||
|
&client->event.error_handle->esp_tls_stack_err,
|
||||||
|
&client->event.error_handle->esp_tls_cert_verify_flags);
|
||||||
|
#endif
|
||||||
|
esp_mqtt_dispatch_event_with_msgid(client);
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user