cURL / Mailing Lists / curl-library / Single Mail

curl-library

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

From: Lijo Antony <lta_at_one.com>
Date: Thu, 13 Dec 2012 10:31:37 +0400

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

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

>
> 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
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-12-13