cURL / Mailing Lists / curl-library / Single Mail

curl-library

RE: SO_REUSEADDR and multi-threaded environment

From: Yehezkel Horowitz <horowity_at_checkpoint.com>
Date: Thu, 3 Jul 2014 06:43:50 +0000

> Each thread in my client application creates a CURL handle using curl_easy_init, sends a request to the server and once the response is received, invokes curl_easy_cleanup on the handle. So, the connection is closed by the thread owning the CURL handle on the client side.

Why you call curl_easy_cleanup and not curl_easy_reset ?

The docs state that curl_easy_reset - "...puts back the handle to the same state as it was in when it was just created with curl_easy_init. It does not change the following information kept in the handle: live connections, the Session ID cache, the DNS cache, the cookies and shares."

> I am invoking curl_easy_cleanup because I am under impression that each CURL handle manages its own connection and they are not shared across CURL handles. Can CURL handles share underlying connections? According to the doc, CURL handles should not be shared across threads at the same time which made me believe that the underlying connections won't be either. 

When using easy API the connections are not shared, but if you need multiple connections in parallel – you might want to consider using the multi API which will allow you to have all your connections managed in a single thread.

HTH

Yehezkel

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2014-07-03