开发者

libcurl - Strange timeout after 5 seconds

开发者 https://www.devze.com 2023-03-07 08:22 出处:网络
I\'m using libcurl to communicate with Twitter and Identi.ca. Everything works perfectly as long as my connection isn\'t busy. But if I\'m downloading a large file, the curl requests timeout after 5 s

I'm using libcurl to communicate with Twitter and Identi.ca. Everything works perfectly as long as my connection isn't busy. But if I'm downloading a large file, the curl requests timeout after 5 seconds.

I've set the following options on the curl handle:

curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 30);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 60);
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 15);

and they make no difference, curl_easy_perform() always returns after 5 seconds. The CURLINFO_RESPONSE_CODE and CURLINFO_HTTP_CONNECTCODE values are always both zero.

Any ideas? Are there any other timeouts I need to set, or is there any reason why the above don't take effect?

EDIT: The return value of curl_easy_perform is CUR开发者_开发知识库LE_OPERATION_TIMEDOUT


I'd say it is because one out of two reasons:

  1. You don't show us the complete program here so you have a set timeout option somewhere else that instructs libcurl to timeout.

  2. Your libcurl version has a bug that makes it misbehave. You didn't say which libcurl version on what platform you're using.

To get really good help, provide a complete source code that repeats the problem against a public URL.


Does the standalone curl program successfully download the file? If not there might be a 5 second request timeout restriction server-side.

You should still be able to download the file in chunks. First grab the HEAD and pull the size of the file, then pull each chunk of the file using the following options:

curl_easy_setopt(curl, CURLOPT_BINARYTRANSFER, 1);
curl_easy_setopt(curl, CURLOPT_RANGE, start_range + "-" + (start_range + chunk_size));

Once you have all the pieces, concatenate them together and you should have your complete file.

0

精彩评论

暂无评论...
验证码 换一张
取 消