]> granicus.if.org Git - curl/commitdiff
- curl_multi_timeout() could return a timeout value of 0 even though nothing
authorDaniel Stenberg <daniel@haxx.se>
Fri, 19 Dec 2008 22:58:22 +0000 (22:58 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 19 Dec 2008 22:58:22 +0000 (22:58 +0000)
  was actually ready to get done, as the internal time resolution is higher
  than the returned millisecond timer. Therefore it could cause applications
  running on fast processors to do short bursts of busy-loops.
  curl_multi_timeout() will now only return 0 if the timeout is actually
  alreay triggered.

CHANGES
RELEASE-NOTES
lib/multi.c

diff --git a/CHANGES b/CHANGES
index 6c48b06f6d8cfe011c6a4de13f5b7fa28f9da45a..b458bb93007fab4f84bea619edfdaa13890f399c 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -7,6 +7,13 @@
                                   Changelog
 
 Daniel Stenberg (19 Dec 2008)
+- curl_multi_timeout() could return a timeout value of 0 even though nothing
+  was actually ready to get done, as the internal time resolution is higher
+  than the returned millisecond timer. Therefore it could cause applications
+  running on fast processors to do short bursts of busy-loops.
+  curl_multi_timeout() will now only return 0 if the timeout is actually
+  alreay triggered.
+
 - Using the libssh2 0.19 function libssh2_session_block_directions(), libcurl
   now has an improved ability to do right when the multi interface (both
   "regular" and multi_socket) is used for SCP and SFTP transfers. This should
index 0f33d2bb4cfcf7844a089ab542f525268f4a51b5..3ce349166e0487208e7354f5366b1ea6f6442913 100644 (file)
@@ -34,6 +34,8 @@ This release includes the following bugfixes:
  o improved connection re-use for subsequent SCP and SFTP transfers
  o multi interface does less busy-loops for SCP and SFTP transfers with libssh2
    0.19 or later
+ o curl_multi_timeout() no longer returns timeout 0 when there's nothing to do
+   yet
 
 This release includes the following known bugs:
 
index f17b3337733764aab8964c652212325461fb4530..97efc706695e0967637f09f38d1397afb687a720 100644 (file)
@@ -1541,6 +1541,7 @@ CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles)
 
   if( CURLM_OK >= returncode )
     update_timer(multi);
+
   return returncode;
 }
 
@@ -1951,9 +1952,19 @@ static CURLMcode multi_timeout(struct Curl_multi *multi,
     /* splay the lowest to the bottom */
     multi->timetree = Curl_splay(tv_zero, multi->timetree);
 
-    if(Curl_splaycomparekeys(multi->timetree->key, now) > 0)
+    if(Curl_splaycomparekeys(multi->timetree->key, now) > 0) {
       /* some time left before expiration */
       *timeout_ms = curlx_tvdiff(multi->timetree->key, now);
+      if(!*timeout_ms)
+        /*
+         * Since we only provide millisecond resolution on the returned value
+         * and the diff might be less than one millisecond here, we don't
+         * return zero as that may cause short bursts of busyloops on fast
+         * processors while the diff is still present but less than one
+         * millisecond! instead we return 1 until the time is ripe.
+         */
+        *timeout_ms=1;
+    }
     else
       /* 0 means immediately */
       *timeout_ms = 0;