diff options
author | Daniel Stenberg <daniel@haxx.se> | 2019-07-29 13:41:00 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2019-08-06 09:33:29 +0200 |
commit | 02346abc32a3995299fa9c2f35b9f0a1d091b045 (patch) | |
tree | de504a328c326fc2ebef7265ddf4de7456fd56be /lib/easy.c | |
parent | cee7639b790f29113759f69c4a955c2ead8bff31 (diff) | |
download | curl-02346abc32a3995299fa9c2f35b9f0a1d091b045.tar.gz |
curl_multi_poll: a sister to curl_multi_wait() that waits more
Repeatedly we see problems where using curl_multi_wait() is difficult or
just awkward because if it has no file descriptor to wait for
internally, it returns immediately and leaves it to the caller to wait
for a small amount of time in order to avoid occasional busy-looping.
This is often missed or misunderstood, leading to underperforming
applications.
This change introduces curl_multi_poll() as a replacement drop-in
function that accepts the exact same set of arguments. This function
works identically to curl_multi_wait() - EXCEPT - for the case when
there's nothing to wait for internally, as then this function will by
itself wait for a "suitable" short time before it returns. This
effectiely avoids all risks of busy-looping and should also make it less
likely that apps "over-wait".
This also changes the curl tool to use this funtion internally when
doing parallel transfers and changes curl_easy_perform() to use it
internally.
Closes #4163
Diffstat (limited to 'lib/easy.c')
-rw-r--r-- | lib/easy.c | 22 |
1 files changed, 3 insertions, 19 deletions
diff --git a/lib/easy.c b/lib/easy.c index 616ad28b8..b8d94c740 100644 --- a/lib/easy.c +++ b/lib/easy.c @@ -602,27 +602,11 @@ static CURLcode easy_transfer(struct Curl_multi *multi) while(!done && !mcode) { int still_running = 0; - bool gotsocket = FALSE; - - mcode = Curl_multi_wait(multi, NULL, 0, 1000, NULL, &gotsocket); - - if(!mcode) { - if(!gotsocket) { - long sleep_ms; - - /* If it returns without any filedescriptor instantly, we need to - avoid busy-looping during periods where it has nothing particular - to wait for */ - curl_multi_timeout(multi, &sleep_ms); - if(sleep_ms) { - if(sleep_ms > 1000) - sleep_ms = 1000; - Curl_wait_ms((int)sleep_ms); - } - } + mcode = curl_multi_poll(multi, NULL, 0, 1000, NULL); + + if(!mcode) mcode = curl_multi_perform(multi, &still_running); - } /* only read 'still_running' if curl_multi_perform() return OK */ if(!mcode && !still_running) { |