esp_https_ota.c: Add fix to return failure if (-1) is returned from esp_http_client_read

Closes https://github.com/espressif/esp-idf/issues/4960
This commit is contained in:
Shubham Kulkarni 2020-03-30 11:52:38 +05:30
parent 22926742be
commit e84ad136b9
1 changed files with 6 additions and 7 deletions

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;