cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: How to deal with multi thread call of curl_multi_socket_action?

From: ؛خصً <sonysuqin_at_gmail.com>
Date: Thu, 13 Dec 2012 16:18:29 +0800

Hi lijo.
Thanks.
It's nice suggestion to use multi interface in a single thread.
All your answers are clear.
But I made a mistake,I was about to ask the CURLMOPT_TIMERFUNCTION callback
with the prototype:

int (*curl_multi_timer_callback)(CURLM *multi, /* multi handle */
                                 long timeout_ms, /* see above */
                                 void *userp); /* private callback pointer */

 Its comments says:

 * Desc: Called by libcurl whenever the library detects a change in the
 * maximum number of milliseconds the app is allowed to wait before
 * curl_multi_socket() or curl_multi_perform() must be called
 * (to allow libcurl's timed events to take place).

I was puzzled here.Why upper layer should implement the callback
manually?What shall the callback do?

2012/12/13 Lijo Antony <lta_at_one.com>

> On 12/13/2012 06:25 AM, ؛خصً wrote:
>
>> Hi :
>> Thanks to lijo.
>>
>> Now I want to write an app which will do asynchronous http call under
>> multi thread circumstance.
>> In every thread I call curl_multi_add_handle to add an easy handle which
>> already initialized to a global multi handle,and I use boost asio as
>> event driver,but when testing I meet some core dump problems and there's
>> no way out now.
>>
>
> If you are using multi interface, only one thread is required for all your
> http transfers. You can achieve better performance and avoid all overheads
> and synchronization issues with multi threading.
>
>
> There're some problems puzzling me:
>> 1.What does CURLOPT_CLOSESOCKETFUNCTION exactly do?What
>> the exact meaning of the second argument 'timevalue' ?Where is it from?
>>
>
> http://curl.haxx.se/libcurl/c/**curl_easy_setopt.html#**
> CURLOPTCLOSESOCKETFUNCTION<http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTCLOSESOCKETFUNCTION>
>
> There is no 'timevalue' argument for CURLOPT_CLOSESOCKETFUNCTION
>
>
> 2.As I run several transfers at the same time,is't neccesary to run a
>> singgle timer for every transfer?
>>
>
> Yes, you *only* need to run a single timer for a multi_handle. Timer is
> not for any single transfer. It is for the multi_handle.
>
>
> 3.Is libcurl thread safe?In other word,is easy hander or multi handle
>> thread safe?
>>
>
> http://curl.haxx.se/libcurl/c/**libcurl-tutorial.html#Multi-**threading<http://curl.haxx.se/libcurl/c/libcurl-tutorial.html#Multi-threading>
>
>
>
>> Or if there is any suggestion to solve my target of using multi handle
>> under multi thread, any will be appreciated.
>>
>>
> I think a better design would be to use a single thread and a single multi
> handle.
>
> -lijo
>
> ------------------------------**------------------------------**-------
> List admin: http://cool.haxx.se/list/**listinfo/curl-library<http://cool.haxx.se/list/listinfo/curl-library>
> Etiquette: http://curl.haxx.se/mail/**etiquette.html<http://curl.haxx.se/mail/etiquette.html>

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-12-13