Skip to content

Commit eb56c82

Browse files
mika-fischergitster
authored andcommitted
http.c: Use timeout suggested by curl instead of fixed 50ms timeout
Recent versions of curl can suggest a period of time the library user should sleep and try again, when curl is blocked on reading or writing (or connecting). Use this timeout instead of always sleeping for 50ms. Signed-off-by: Mika Fischer <[email protected]> Helped-by: Daniel Stenberg <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6f9dd67 commit eb56c82

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

http.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,13 +651,29 @@ void run_active_slot(struct active_request_slot *slot)
651651
}
652652

653653
if (slot->in_use && !data_received) {
654+
#if LIBCURL_VERSION_NUM >= 0x070f04
655+
long curl_timeout;
656+
curl_multi_timeout(curlm, &curl_timeout);
657+
if (curl_timeout == 0) {
658+
continue;
659+
} else if (curl_timeout == -1) {
660+
select_timeout.tv_sec = 0;
661+
select_timeout.tv_usec = 50000;
662+
} else {
663+
select_timeout.tv_sec = curl_timeout / 1000;
664+
select_timeout.tv_usec = (curl_timeout % 1000) * 1000;
665+
}
666+
#else
667+
select_timeout.tv_sec = 0;
668+
select_timeout.tv_usec = 50000;
669+
#endif
670+
654671
max_fd = -1;
655672
FD_ZERO(&readfds);
656673
FD_ZERO(&writefds);
657674
FD_ZERO(&excfds);
658675
curl_multi_fdset(curlm, &readfds, &writefds, &excfds, &max_fd);
659-
select_timeout.tv_sec = 0;
660-
select_timeout.tv_usec = 50000;
676+
661677
select(max_fd+1, &readfds, &writefds, &excfds, &select_timeout);
662678
}
663679
}

0 commit comments

Comments
 (0)