Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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

share|improve this question

2 Answers 2

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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.
{"cc_re__cc_re__cc_by_sa_3_0": ["sites in the Stack Exchange network\">Area 51</a></li>\r\n                        <li><a href=\"//careers.stackoverflow.com?utm_source=stackoverflow.com&amp;utm_medium=site-ui&amp;utm_campaign=footerlink\">Stack Overflow Careers</a></li>\r\n                    \r\n                </ol>\r\n            </td>\r\n    </tr>\r\n</table>\r\n                </div>\r\n            </div>\r\n\r\n            <div id=\"copyright\">\r\n                site design / logo &#169; 2014 stack exchange inc; user contributions licensed under <a href=\"http://creativecommons.org/licenses/by-sa/3.0/\" rel=\"license\">cc by-sa 3.0</a>                   with <a href=\"http://blog.stackoverflow.com/2009/06/attribution-required/\" rel=\"license\">attribution required</a>\r\n            </div>\r\n            <div id=\"svnrev\">\r\n                rev 2014.10.21.1957\r\n            </div>\r\n            \r\n        </div>\r\n    </div>\r\n    <noscript>\r\n        <div id=\"noscript-warning\">Stack Overflow works best with JavaScript enabled<img src=\"http://pixel.quantserve.com/pixel/p-c1rF4kxgLUzNc.gif\" alt=\"\" class=\"dno\"></div>\r\n    </no"], "copyright__copyright__copyright": ["k of the file using the following options:\n\ncurl_easy_setopt(curl, CURLOPT_BINARYTRANSFER, 1);\ncurl_easy_setopt(curl, CURLOPT_RANGE, start_range + \"-\" + (start_range + chunk_size));\n\nOnce you have all the pieces, concatenate them together and you should have your complete file.\n\nshare|improve this answer\n\nYour Answer\n\n\u00a0\ndiscard\n\nBy posting your answer, you agree to the privacy policy and terms of service.\n\nNot the answer you're looking for? Browse other questions tagged or ask your own question."]}