Code

http.c: Use timeout suggested by curl instead of fixed 50ms timeout
authorMika Fischer <mika.fischer@zoopnet.de>
Fri, 4 Nov 2011 14:19:26 +0000 (15:19 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 4 Nov 2011 17:46:56 +0000 (10:46 -0700)
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>
http.c

diff --git a/http.c b/http.c
index a815f628b92649a82e67c9d486312bdec4892051..924be52add88690295cbbb27c3eca34bb6ec8f5a 100644 (file)
--- a/http.c
+++ b/http.c
@@ -651,13 +651,29 @@ void run_active_slot(struct active_request_slot *slot)
                }
 
                if (slot->in_use && !data_received) {
+#if LIBCURL_VERSION_NUM >= 0x070f04
+                       long curl_timeout;
+                       curl_multi_timeout(curlm, &curl_timeout);
+                       if (curl_timeout == 0) {
+                               continue;
+                       } else if (curl_timeout == -1) {
+                               select_timeout.tv_sec  = 0;
+                               select_timeout.tv_usec = 50000;
+                       } else {
+                               select_timeout.tv_sec  =  curl_timeout / 1000;
+                               select_timeout.tv_usec = (curl_timeout % 1000) * 1000;
+                       }
+#else
+                       select_timeout.tv_sec  = 0;
+                       select_timeout.tv_usec = 50000;
+#endif
+
                        max_fd = -1;
                        FD_ZERO(&readfds);
                        FD_ZERO(&writefds);
                        FD_ZERO(&excfds);
                        curl_multi_fdset(curlm, &readfds, &writefds, &excfds, &max_fd);
-                       select_timeout.tv_sec = 0;
-                       select_timeout.tv_usec = 50000;
+
                        select(max_fd+1, &readfds, &writefds, &excfds, &select_timeout);
                }
        }