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 <mika.fischer@zoopnet.de> Helped-by: Daniel Stenberg <daniel@haxx.se> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Mika Fischer committed Nov 4, 2011 at 15:19 UTC eb56c82163487fe07ba04f2b365a557282cbd766
1 file changed +18 -2
http.c
+18 -2
@@ -651,13 +651,29 @@ void run_active_slot(struct active_request_slot *slot)
651 }
652
653 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 +
671 max_fd = -1;
672 FD_ZERO(&readfds);
673 FD_ZERO(&writefds);
674 FD_ZERO(&excfds);
675 curl_multi_fdset(curlm, &readfds, &writefds, &excfds, &max_fd);
659 - select_timeout.tv_sec = 0;
660 - select_timeout.tv_usec = 50000;
676 +
677 select(max_fd+1, &readfds, &writefds, &excfds, &select_timeout);
678 }
679 }