Skip to content

Commit

Permalink
Increasing sleep intervals. Add timeout limit
Browse files Browse the repository at this point in the history
  • Loading branch information
Alejandro Alfonso committed May 17, 2021
1 parent 239b4c5 commit e56121e
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/DownloadURL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <unistd.h>
#endif

#define MAX_TIMEOUT 300000

std::string DownloadURL(std::string URL)
{
//Initialize CURL
Expand Down Expand Up @@ -52,15 +54,20 @@ std::string DownloadURL(std::string URL)
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, pagefile);
/* get it! */
CURLcode res = CURLE_OK;
do //Retry until we get it, every 10 seconds
unsigned int i = 0;
do //Retry until we get it, every increasing 5-second intervals
{
if (res != CURLE_OK)
if (res == CURLE_HTTP_RETURNED_ERROR) //Only repeat on HTTP errors
{
Sleep(5000);
Sleep(5000 * i);
}

res = curl_easy_perform(curl_handle); /* code */
} while (res != CURLE_OK);
res = curl_easy_perform(curl_handle);
i++;
} while (res != CURLE_OK && 5000 * i < MAX_TIMEOUT);
//Show that we reached timeout limit
if (res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() timeout error: %s\n", curl_easy_strerror(res));

/* close the header file */
fclose(pagefile);
Expand Down

0 comments on commit e56121e

Please sign in to comment.