cURL: idle timeout interval more than specified value
I am using libcurl
to create an http connection to a server. During initialization I have specified an idle timeout value of 5 seconds and also specified as progress callback function. I was expecting cURL to abort the connection after 5 seconds of inactivity and to stop calling the progress callback but I found that curl times out after around 15 seconds. Why is curl taking more time to timeout than I what I have specified? Setting timeout to a larger value does n开发者_JAVA技巧ot help. If I specify 100 secs, it timesout after 105 secs of inactivity.
code = s_curl_easy_setopt(m_curl_handle, CURLOPT_NOPROGRESS, 0);
assert(code == CURLE_OK);
code = s_curl_easy_setopt(m_curl_handle, CURLOPT_PROGRESSFUNCTION, progress_callback);
assert(code == CURLE_OK);
EDIT: The timeout code
//this will set the timeout for quitting in case the network goes down
code = s_curl_easy_setopt(m_curl_handle, CURLOPT_LOW_SPEED_LIMIT, 1);
code = s_curl_easy_setopt(m_curl_handle, CURLOPT_LOW_SPEED_TIME, m_idle_timeout);
I have figured this one out. cURL updates its progress approximately one per second. To calculate idle timeout cURL calculates the average bytes/sec over 6 updates and compares it with the CURLOPT_LOW_SPEED_LIMIT
. If this value is less than CURLOPT_LOW_SPEED_LIMIT
for more than CURLOPT_LOW_SPEED_TIME
seconds at a stretch, it times out. So if the CURLOPT_LOW_SPEED_TIME
is 5 seconds, cURL will calculate the average bytes/sec over the last 6 progress updates (approx 5 secs) and then check if it is less than CURLOPT_LOW_SPEED_LIMIT
for at least 5 seconds, thus taking total time of approx. 10 seconds.
(1) Libcurl docs on the PROGRESSFUNCTION say:
This function gets called by libcurl instead of its internal equivalent with a frequent interval during operation (roughly once per second or sooner) no matter if data is being transfered or not.
(2) Which "timeout" are you referring to? The only one I could find related to a connection timeout, which would not pertain to terminating the connection after it was established, and no data was sent - as you seem to be implying.
精彩评论