Blame SOURCES/0011-curl-7.29.0-0feeab78.patch

c260e0
From d3036f34cce421990e8268ee4bbfc0d9f5ceb054 Mon Sep 17 00:00:00 2001
c260e0
From: Daniel Stenberg <daniel@haxx.se>
c260e0
Date: Thu, 13 Jun 2013 19:27:12 +0200
c260e0
Subject: [PATCH] curl_easy_perform: avoid busy-looping
c260e0
c260e0
When curl_multi_wait() finds no file descriptor to wait for, it returns
c260e0
instantly and this must be handled gracefully within curl_easy_perform()
c260e0
or cause a busy-loop. Starting now, repeated fast returns without any
c260e0
file descriptors is detected and a gradually increasing sleep will be
c260e0
used (up to a max of 1000 milliseconds) before continuing the loop.
c260e0
c260e0
Bug: http://curl.haxx.se/bug/view.cgi?id=1238
c260e0
Reported-by: Miguel Angel
c260e0
c260e0
[upstream commit 0feeab7802dd2a6465d22d153d8d36b2cca99b96]
c260e0
c260e0
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
c260e0
---
c260e0
 lib/easy.c |   25 +++++++++++++++++++++++++
c260e0
 1 files changed, 25 insertions(+), 0 deletions(-)
c260e0
c260e0
diff --git a/lib/easy.c b/lib/easy.c
c260e0
index 2739598..a7051dd 100644
c260e0
--- a/lib/easy.c
c260e0
+++ b/lib/easy.c
c260e0
@@ -410,6 +410,9 @@ CURLcode curl_easy_perform(CURL *easy)
c260e0
   bool done = FALSE;
c260e0
   int rc;
c260e0
   struct SessionHandle *data = easy;
c260e0
+  int without_fds = 0;  /* count number of consecutive returns from
c260e0
+                           curl_multi_wait() without any filedescriptors */
c260e0
+  struct timeval before;
c260e0
 
c260e0
   if(!easy)
c260e0
     return CURLE_BAD_FUNCTION_ARGUMENT;
c260e0
@@ -445,6 +448,7 @@ CURLcode curl_easy_perform(CURL *easy)
c260e0
     int still_running;
c260e0
     int ret;
c260e0
 
c260e0
+    before = curlx_tvnow();
c260e0
     mcode = curl_multi_wait(multi, NULL, 0, 1000, &ret;;
c260e0
 
c260e0
     if(mcode == CURLM_OK) {
c260e0
@@ -453,6 +457,27 @@ CURLcode curl_easy_perform(CURL *easy)
c260e0
         code = CURLE_RECV_ERROR;
c260e0
         break;
c260e0
       }
c260e0
+      else if(ret == 0) {
c260e0
+        struct timeval after = curlx_tvnow();
c260e0
+        /* If it returns without any filedescriptor instantly, we need to
c260e0
+           avoid busy-looping during periods where it has nothing particular
c260e0
+           to wait for */
c260e0
+        if(curlx_tvdiff(after, before) <= 10) {
c260e0
+          without_fds++;
c260e0
+          if(without_fds > 2) {
c260e0
+            int sleep_ms = without_fds * 50;
c260e0
+            if(sleep_ms > 1000)
c260e0
+              sleep_ms = 1000;
c260e0
+            Curl_wait_ms(sleep_ms);
c260e0
+          }
c260e0
+        }
c260e0
+        else
c260e0
+          /* it wasn't "instant", restart counter */
c260e0
+          without_fds = 0;
c260e0
+      }
c260e0
+      else
c260e0
+        /* got file descriptor, restart counter */
c260e0
+        without_fds = 0;
c260e0
 
c260e0
       mcode = curl_multi_perform(multi, &still_running);
c260e0
     }
c260e0
-- 
c260e0
1.7.1
c260e0