CURL: The idle timeout interval is greater than the set value.

I use libcurl to create an http connection to the server. During initialization, I set a timeout value in standby mode of 5 seconds and also indicated a callback execution function. I expected cURL to terminate the connection after 5 seconds of inactivity and stop calling the progress callback, but I found that the curl expires after about 15 seconds. Why does curl take longer than me, as I pointed out? Setting a timeout to a larger value does not help. If I specify 100 seconds, it will expire after 105 seconds 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: 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); 
+4
source share
2 answers

I get it. cURL updates its progress approximately once per second. To calculate the idle timeout, cURL calculates the average value of bytes / sec from 6 updates and compares it with CURLOPT_LOW_SPEED_LIMIT . If this value is less than CURLOPT_LOW_SPEED_LIMIT for more than CURLOPT_LOW_SPEED_TIME seconds in a stretch, time expires. Thus, if CURLOPT_LOW_SPEED_TIME is 5 seconds, cURL will calculate the average bytes / sec for the last 6 progress updates (approximately 5 seconds), and then check if it is less than CURLOPT_LOW_SPEED_LIMIT at least 5 seconds, so the total time is approx. 10 Seconds.

+6
source

(1) Libcurl docs on PROGRESSFUNCTION says:

This function is called by libcurl instead of its internal equivalent at frequent intervals during (approximately once per second or earlier) regardless of whether the data is transferred or not.

(2) What β€œtimeout” do you mean? The only thing I could find was a connection timeout related to the connection termination after it was established and no data was sent - as you seem to imply.

0
source

All Articles