cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Questions on using the curl multi interface

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Thu, 2 Sep 2010 23:29:02 +0200 (CEST)

On Thu, 2 Sep 2010, lali .cpp wrote:

> 1. Initialize multi handle (curl_multi_init)
> 2. setopt on multi handle for CURLMOPT_MAXCONNECTS
> 3. Initialize easy handles (curl_easy_init)
> 4. Do setopts on easy handles i.e url to fetch, connnection establishment
> timeout etc.

I trust you do curl_multi_add_handle() between 4 and 5!

> 5. Do multiperform, wait on select to know that a fd is ready for I/O.
> perform I/O(using curl multi perform) or break out of loop on select timeout

No, don't break out on timeout. If you want all transfers to complete, you
wait until the transfers are done. Either by checking the running_handles
integer curl_multi_perform() stores, or by using curl_multi_info_read().

See for example http://curl.haxx.se/libcurl/c/multi-double.html

> So following are my questions:-
> 1) Is this how curl multi interface needs to be used or should the curl easy
> handles be reinitialized every time i.e instead of step 4 go to step 3?

Options for easy handles remain set so you can re-use them at will without
having to set the same options again.

> 2) Can I do the following:- Initialize the easy handle, use it n times in a
> multihandle as in the above mentioned 7 steps and then after nth time I go
> to step 3 instead of 4( Also do curl_easy_cleanup before going to step 3)?

Sure. Or you curl_easy_reset() the handle instead of cleanup/init.

-- 
  / daniel.haxx.se
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2010-09-02