diff options
author | Constantine Sapuntzakis <csapuntz@gmail.com> | 2010-07-12 19:19:31 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2010-07-12 19:19:31 +0200 |
commit | d4e64041352a4454dc0a961d125794692a913136 (patch) | |
tree | 4fed8cce0d32737c3c5756174eca54778f892f18 | |
parent | 3992309285cdb75076744aa8f9fb0f1cbd5dade5 (diff) |
multi: fix condition that remove timers before trigger
curl_multi perform has two phases: run through every easy handle calling
multi_runsingle and remove expired timers (timer removal).
If a small timer (e.g. 1-10ms) is set during multi_runsingle, then it's
possible that the timer has passed by when the timer removal runs. The
timer which was just added is then removed. This will potentially cause
the timer list to be empty and cause the next call to curl_multi_timeout
to return -1. Ideally, curl_multi_timeout should return 0 in this case.
One way to fix this is to move the struct timeval now = Curl_tvnow(); to
the top of curl_multi_perform. The change does that.
-rw-r--r-- | lib/multi.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/multi.c b/lib/multi.c index 9273f8dcf..f64577f56 100644 --- a/lib/multi.c +++ b/lib/multi.c @@ -1570,6 +1570,7 @@ CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles) struct Curl_one_easy *easy; CURLMcode returncode=CURLM_OK; struct Curl_tree *t; + struct timeval now = Curl_tvnow(); if(!GOOD_MULTI_HANDLE(multi)) return CURLM_BAD_HANDLE; @@ -1607,10 +1608,13 @@ CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles) * Simply remove all expired timers from the splay since handles are dealt * with unconditionally by this function and curl_multi_timeout() requires * that already passed/handled expire times are removed from the splay. + * + * It is important that the 'now' value is set at the entry of this function + * and not for the current time as it may have ticked a little while since + * then and then we risk this loop to remove timers that actually have not + * been handled! */ do { - struct timeval now = Curl_tvnow(); - multi->timetree = Curl_splaygetbest(now, multi->timetree, &t); if(t) { struct SessionHandle *d = t->payload; |