Merge branch 'bugfix/http_client_read_v4.0' into 'release/v4.0'

Fix error handling in esp_http_client_read and esp_https_ota_perform (v4.0)

See merge request espressif/esp-idf!9204
This commit is contained in:
Mahavir Jain 2020-07-08 17:19:50 +08:00
commit 576957b17d
4 changed files with 13 additions and 10 deletions

View File

@ -860,7 +860,11 @@ 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);
}
return ridx;
if (rlen < 0 && ridx == 0) {
return ESP_FAIL;
} else {
return ridx;
}
}
res_buffer->output_ptr = buffer + ridx;
http_parser_execute(client->parser, client->parser_settings, res_buffer->data, rlen);

View File

@ -78,10 +78,7 @@ static esp_err_t _http_handle_response_code(esp_http_client_handle_t http_client
* to clear the response buffer of http_client.
*/
int data_read = esp_http_client_read(http_client, upgrade_data_buf, DEFAULT_OTA_BUF_SIZE);
if (data_read < 0) {
ESP_LOGE(TAG, "Error: SSL data read error");
return ESP_FAIL;
} else if (data_read == 0) {
if (data_read <= 0) {
return ESP_OK;
}
}
@ -235,10 +232,10 @@ esp_err_t esp_https_ota_get_img_desc(esp_https_ota_handle_t https_ota_handle, es
(handle->ota_upgrade_buf + bytes_read),
data_read_size);
/*
* As esp_http_client_read never returns negative error code, we rely on
* As esp_http_client_read doesn't return negative error code if select fails, we rely on
* `errno` to check for underlying transport connectivity closure if any
*/
if (errno == ENOTCONN || errno == ECONNRESET || errno == ECONNABORTED) {
if (errno == ENOTCONN || errno == ECONNRESET || errno == ECONNABORTED || data_read < 0) {
ESP_LOGE(TAG, "Connection closed, errno = %d", errno);
break;
}
@ -294,7 +291,7 @@ esp_err_t esp_https_ota_perform(esp_https_ota_handle_t https_ota_handle)
*/
bool is_recv_complete = esp_https_ota_is_complete_data_received(https_ota_handle);
/*
* As esp_http_client_read never returns negative error code, we rely on
* As esp_http_client_read doesn't return negative error code if select fails, we rely on
* `errno` to check for underlying transport connectivity closure if any.
* Incase the complete data has not been received but the server has sent
* an ENOTCONN or ECONNRESET, failure is returned. We close with success
@ -309,6 +306,8 @@ esp_err_t esp_https_ota_perform(esp_https_ota_handle_t https_ota_handle)
ESP_LOGI(TAG, "Connection closed");
} else if (data_read > 0) {
return _ota_write(handle, (const void *)handle->ota_upgrade_buf, data_read);
} else {
return ESP_FAIL;
}
handle->state = ESP_HTTPS_OTA_SUCCESS;
break;

View File

@ -1,4 +1,4 @@
CONFIG_EXAMPLE_FIRMWARE_UPGRADE_URL="FROM_STDIN"
CONFIG_EXAMPLE_SKIP_COMMON_NAME_CHECK=y
CONFIG_EXAMPLE_SKIP_VERSION_CHECK=y
CONFIG_EXAMPLE_OTA_RECV_TIMEOUT=2000
CONFIG_EXAMPLE_OTA_RECV_TIMEOUT=3000

View File

@ -1,4 +1,4 @@
CONFIG_EXAMPLE_FIRMWARE_UPG_URL="FROM_STDIN"
CONFIG_EXAMPLE_SKIP_COMMON_NAME_CHECK=y
CONFIG_EXAMPLE_SKIP_VERSION_CHECK=y
CONFIG_EXAMPLE_OTA_RECV_TIMEOUT=2000
CONFIG_EXAMPLE_OTA_RECV_TIMEOUT=3000