Skip to content

Commit

Permalink
improved performance when encountering HTTP 429
Browse files Browse the repository at this point in the history
  • Loading branch information
fangfufu committed Apr 26, 2019
1 parent 9717d01 commit 39820e3
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ static void curl_process_msgs(CURLMsg *curl_msg, int n_running_curl, int n_mesgs
{
(void) n_running_curl;
(void) n_mesgs;
static int slept = 0;
if (curl_msg->msg == CURLMSG_DONE) {
TransferStruct *transfer;
CURL *curl = curl_msg->easy_handle;
Expand All @@ -103,14 +104,20 @@ static void curl_process_msgs(CURLMsg *curl_msg, int n_running_curl, int n_mesgs
long http_resp = 0;
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_resp);
if (http_resp == HTTP_TOO_MANY_REQUESTS) {
fprintf(stderr, "curl_process_msgs(): HTTP 429\n");
sleep(HTTP_429_WAIT);
fprintf(stderr, "curl_process_msgs(): Finished sleeping\n");
if (!slept) {
fprintf(stderr, "curl_process_msgs(): HTTP 429, sleeping\n");
sleep(HTTP_429_WAIT);
slept = 1;
} else {
fprintf(stderr,
"curl_process_msgs(): HTTP 429, slept already\n");
}
/* Re-add the link into the queue, if it is a file stat query */
if (transfer->type == FILESTAT) {
Link_get_stat(transfer->link);
}
fprintf(stderr, "curl_process_msgs(): Link re-added\n");
} else {
slept = 0;
}

if (curl_msg->data.result) {
Expand Down

0 comments on commit 39820e3

Please sign in to comment.