Kazade
Kazade

Reputation: 1327

libcurl - Strange timeout after 5 seconds

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 CURLE_OPERATION_TIMEDOUT

Upvotes: 3

Views: 4978

Answers (2)

seanhodges
seanhodges

Reputation: 17524

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.

Upvotes: 0

Daniel Stenberg
Daniel Stenberg

Reputation: 58034

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.

Upvotes: 1

Related Questions