Reputation: 41
I try to implement multi-threaded downloading using CURL library.
I prepare N threads (easy handles that download different ranges) and invoke curl_multi_perform(multiHandle, &running) after that.
My questions
Upvotes: 4
Views: 3906
Reputation: 58014
The libcurl multi interface is not threaded. It does parallel transfers in the same thread!
You can add easy handles to the multi handle at any time you like. Just call curl_multi_perform() then and it'll drive all added easy handles. You can also remove handles at any time.
You should use curl_multi_info_read() to figure out which handles that have completed. Until they are completed, you can consider them in use. If you want to put a easy handle back to the multi handle to do another transfer, just remove it from the handle (possibly set new options) and add it again.
See also http://curl.se/libcurl/c/example.html for lots of libcurl examples, including a bunch that uses the multi interface. The general multi interface "tutorial" style docs is here: http://curl.se/libcurl/c/libcurl-multi.html
Upvotes: 5