forked from espressif/esp-mqtt
Merge branch 'bugfix/read_error_event' into 'master'
MQTT: add dispatch error event for read errors See merge request espressif/esp-mqtt!75
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 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 void esp_mqtt_client_dispatch_tls_error(esp_mqtt_client_handle_t client);
|
||||
|
||||
|
||||
#if MQTT_ENABLE_SSL
|
||||
enum esp_mqtt_ssl_cert_key_api {
|
||||
@ -849,15 +851,7 @@ static esp_err_t mqtt_write_data(esp_mqtt_client_handle_t client)
|
||||
client->config->network_timeout_ms);
|
||||
// client->mqtt_state.pending_msg_type = mqtt_get_type(client->mqtt_state.outbound_message->data);
|
||||
if (write_len <= 0) {
|
||||
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);
|
||||
esp_mqtt_client_dispatch_tls_error(client);
|
||||
ESP_LOGE(TAG, "Error write data or timeout, written len = %d, errno=%d", write_len, errno);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
@ -1133,6 +1127,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);
|
||||
return 1;
|
||||
err:
|
||||
esp_mqtt_client_dispatch_tls_error(client);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1309,15 +1304,7 @@ static void esp_mqtt_task(void *pv)
|
||||
client->config->port,
|
||||
client->config->network_timeout_ms) < 0) {
|
||||
ESP_LOGE(TAG, "Error transport connect");
|
||||
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);
|
||||
esp_mqtt_client_dispatch_tls_error(client);
|
||||
esp_mqtt_abort_connection(client);
|
||||
break;
|
||||
}
|
||||
@ -1723,3 +1710,17 @@ esp_err_t esp_mqtt_client_register_event(esp_mqtt_client_handle_t client, esp_mq
|
||||
return ESP_FAIL;
|
||||
#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