【发布时间】:2010-11-12 12:06:25
【问题描述】:
我正在使用libcurl 创建到服务器的 http 连接。在初始化期间,我指定了 5 秒的空闲超时值,并且还指定了进度回调函数。我期待 cURL 在 5 秒不活动后中止连接并停止调用进度回调,但我发现 curl 在大约 15 秒后超时。为什么 curl 超时的时间比我指定的时间长?将超时设置为更大的值没有帮助。如果我指定 100 秒,它会在 105 秒不活动后超时。
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);
编辑:超时代码
//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);
【问题讨论】: