diff mbox series

channel_curl: keep retrying file download after connection lost

Message ID DM5PR07MB3514385BA441D3F8B3633E04F8809@DM5PR07MB3514.namprd07.prod.outlook.com
State Accepted
Headers show
Series channel_curl: keep retrying file download after connection lost | expand

Commit Message

Martin Mena Oct. 22, 2021, 7:24 p.m. UTC
This prevents the local cache from being deleted when the connection to
the server is not reliable, which allows large files to be downloaded
in multiple sessions.

Signed-off-by: Martin Mena <martin.mena@outlook.com>
---
 corelib/channel_curl.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

Stefano Babic Oct. 25, 2021, 3:07 p.m. UTC | #1
Hi Martin,

On 22.10.21 21:24, Martin Mena wrote:
> This prevents the local cache from being deleted when the connection to
> the server is not reliable, which allows large files to be downloaded
> in multiple sessions.
> 
> Signed-off-by: Martin Mena <martin.mena@outlook.com>
> ---
>   corelib/channel_curl.c | 9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/corelib/channel_curl.c b/corelib/channel_curl.c
> index fba773b..4fbec5a 100644
> --- a/corelib/channel_curl.c
> +++ b/corelib/channel_curl.c
> @@ -1230,7 +1230,14 @@ channel_op_res_t channel_get_file(channel_t *this, void *data)
>   
>   		curlrc = curl_easy_perform(channel_curl->handle);
>   		result = channel_map_curl_error(curlrc);
> -		if ((result != CHANNEL_OK) && (result != CHANNEL_EAGAIN)) {
> +		if (result == CHANNEL_ENONET) {
> +			WARN("Lost connection. Retrying after %d seconds.",
> +					channel_data->retry_sleep);
> +			if (sleep(channel_data->retry_sleep) > 0) {
> +				TRACE("Channel's sleep got interrupted, "
> +					"retrying nonetheless now.");
> +			}
> +		} else if ((result != CHANNEL_OK) && (result != CHANNEL_EAGAIN)) {
>   			ERROR("Channel operation returned error (%d): '%s'",
>   			      curlrc, curl_easy_strerror(curlrc));
>   			goto cleanup_file;
> 

It seems ok to me, if there is no netweork it should run in the loop 
until tryout exceeds the configuration - I do not see issues.

Acked-by: Stefano Babic <sbabic@denx.de>

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/corelib/channel_curl.c b/corelib/channel_curl.c
index fba773b..4fbec5a 100644
--- a/corelib/channel_curl.c
+++ b/corelib/channel_curl.c
@@ -1230,7 +1230,14 @@  channel_op_res_t channel_get_file(channel_t *this, void *data)
 
 		curlrc = curl_easy_perform(channel_curl->handle);
 		result = channel_map_curl_error(curlrc);
-		if ((result != CHANNEL_OK) && (result != CHANNEL_EAGAIN)) {
+		if (result == CHANNEL_ENONET) {
+			WARN("Lost connection. Retrying after %d seconds.",
+					channel_data->retry_sleep);
+			if (sleep(channel_data->retry_sleep) > 0) {
+				TRACE("Channel's sleep got interrupted, "
+					"retrying nonetheless now.");
+			}
+		} else if ((result != CHANNEL_OK) && (result != CHANNEL_EAGAIN)) {
 			ERROR("Channel operation returned error (%d): '%s'",
 			      curlrc, curl_easy_strerror(curlrc));
 			goto cleanup_file;