diff options
author | Mole Shang <[email protected]> | 2023-08-07 21:50:10 +0800 |
---|---|---|
committer | Mole Shang <[email protected]> | 2023-08-07 22:59:18 +0800 |
commit | f9b502b5fdfeb7e11e3eacc158b41748623efd56 (patch) | |
tree | b2e7f840685feb246139860ff754f37e8abc6e40 /src/process_url.c | |
parent | 1a5e67daaae24b2bdf17d3ea04fbbdf5e0ab9a60 (diff) | |
download | hinata-f9b502b5fdfeb7e11e3eacc158b41748623efd56.tar.gz hinata-f9b502b5fdfeb7e11e3eacc158b41748623efd56.tar.bz2 hinata-f9b502b5fdfeb7e11e3eacc158b41748623efd56.zip |
process_url: add retries while downloading
Diffstat (limited to 'src/process_url.c')
-rw-r--r-- | src/process_url.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/process_url.c b/src/process_url.c index b6fa730..71fdacd 100644 --- a/src/process_url.c +++ b/src/process_url.c @@ -1,3 +1,4 @@ +#include "constants.h" #include <curl/curl.h> #include <curl/easy.h> #include <curl/header.h> @@ -46,7 +47,6 @@ static CURLU *h; static bool logerr_b(CURLcode r) { if (r && !corrupted) { LOG("libcurl", "Error %d: %s\n", r, ERRTOSTRING(r)); - corrupted = true; } return r; } @@ -84,7 +84,6 @@ static bool logerr_h(CURLHcode r) { break; } LOG("libcurl", "Header Error %d: %s\n", r, err_str); - corrupted = true; } return r; } @@ -292,7 +291,7 @@ static int pull_part(void *a) { sprintf(curl_c->partfn.str[n], "%s.%d", curl_c->outfn, n); DEBUG_PRINT("[THRD %hhu] partfn: %s, range: %s\n", n, get_str_element(&curl_c->partfn, n), ti->range); - { + for (unsigned char retry = 0;; retry++) { curl_c->fplist[n] = fopen(get_str_element(&curl_c->partfn, n), "wb+"); CURL *curl; @@ -313,6 +312,14 @@ static int pull_part(void *a) { append_log("[THRD %hhu] File downloaded.\n", n); curl_easy_cleanup(curl); logerr(res); + if (!res) { + break; + } + if (retry + 1 == MAX_RETRY) { + append_log("Error after %d retries, exiting...\n", MAX_RETRY); + corrupted = true; + break; + } } mtx_lock(&mtx); curl_c->success_thrd += 1; |