From 718d2e5f19125ec7eaea618c3795a64ba42d126c Mon Sep 17 00:00:00 2001 From: Vikram Dattu Date: Mon, 2 Aug 2021 17:04:14 +0530 Subject: [PATCH] esp_http_client: Fixed handling of EAGAIN return For https connection `ESP_TLS_ERR_SSL_WANT_READ` of esp_transport_read was getting treated as error. Treated this as a timeout to fix connection abort issue! Also handled http connection EAGAIN with `errno == EAGAIN` check. Signed-off-by: Vikram Dattu --- components/esp_http_client/esp_http_client.c | 13 ++++++++++--- components/esp_https_ota/src/esp_https_ota.c | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/components/esp_http_client/esp_http_client.c b/components/esp_http_client/esp_http_client.c index 9c8c93c792..43b255ad16 100644 --- a/components/esp_http_client/esp_http_client.c +++ b/components/esp_http_client/esp_http_client.c @@ -906,11 +906,18 @@ int esp_http_client_read(esp_http_client_handle_t client, char *buffer, int len) } ESP_LOG_LEVEL(sev, TAG, "esp_transport_read returned:%d and errno:%d ", rlen, errno); } - if (rlen < 0 && ridx == 0 && !esp_http_client_is_complete_data_received(client)) { - return ESP_FAIL; - } else { +#ifdef CONFIG_ESP_HTTP_CLIENT_ENABLE_HTTPS + if (rlen == ESP_TLS_ERR_SSL_WANT_READ || errno == EAGAIN) { +#else + if (errno == EAGAIN) { +#endif + ESP_LOGD(TAG, "Received EAGAIN! rlen = %d, errno %d", rlen, errno); return ridx; } + if (rlen < 0 && ridx == 0 && !esp_http_client_is_complete_data_received(client)) { + return ESP_FAIL; + } + return ridx; } res_buffer->output_ptr = buffer + ridx; http_parser_execute(client->parser, client->parser_settings, res_buffer->data, rlen); diff --git a/components/esp_https_ota/src/esp_https_ota.c b/components/esp_https_ota/src/esp_https_ota.c index 75fdb9dcb0..f5533b9603 100644 --- a/components/esp_https_ota/src/esp_https_ota.c +++ b/components/esp_https_ota/src/esp_https_ota.c @@ -308,6 +308,7 @@ esp_err_t esp_https_ota_perform(esp_https_ota_handle_t https_ota_handle) } else if (data_read > 0) { return _ota_write(handle, (const void *)handle->ota_upgrade_buf, data_read); } else { + ESP_LOGE(TAG, "data read %d, errno %d", data_read, errno); return ESP_FAIL; } handle->state = ESP_HTTPS_OTA_SUCCESS;