diff options
| -rw-r--r-- | src/constants.h | 1 | ||||
| -rw-r--r-- | src/process_url.c | 13 | 
2 files changed, 11 insertions, 3 deletions
| diff --git a/src/constants.h b/src/constants.h index 2d49ffd..0158e7e 100644 --- a/src/constants.h +++ b/src/constants.h @@ -6,6 +6,7 @@  #define MAX_THREAD 6  #define MAX_THREAD_SIZE 10485760 +#define MAX_RETRY 3  #define CEIL_DIV(a, b) (((a) + (b)-1) / (b))  #define MAX(x, y) ((x) > (y)) ? (x) : (y) 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; | 
