cURL / Mailing Lists / curl-library / Single Mail

curl-library

curl_multi_wait returns immediately when using bandwidth limit

From: Robert Wojciechowski <rwojciechowski_at_skylable.com>
Date: Thu, 22 May 2014 14:51:39 +0200

Hi,

I am using libcurl multi interface. There is a loop that use
curl_multi_wait() function to wait for sockets to be ready with
bandwidth limits enabled. Problem appears when bandwidth limit is small,
curl_multi_wait() returns immediately. Then the effect is a busy loop.

In my code I use:
curl_multi_timeout(e->multi, &timeout);
I get expected timeout that I should wait, and then I do
curl_multi_wait(e->multi, NULL, 0, timeout, &numfds);
and this function returns immediately with numfds set to 0.

According to docs numfds is set to 0 what would mean no sockets to wait
for. But actually there are running socktes, but curl is exceeding
bandwidth limit.

I was digging little in libcurl code and found out that
curl_multi_wait() gets a bitmap of sockets from multi_getsock()
function. The problem is that session handle is being checked for
particular state. And one of the states is CURLM_STATE_TOOFAST that
causes function to return 0 running socket fds bitmap. As an implication
curl_multi_wait() return 0 for numfds and refuse to wait.

Is'n it a confusing behavior? I think curl_multi_wait() should handle
this particular case. Use sleeping instead of select() and do not return
immediately or at least return an error code or set a message, because
using too high bandwidth does not mean that there are no sockets to wait.

Cheers,
Robert
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2014-05-22