cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: A problem of using CURLOPT_RESOLVE with multi interface

From: Kim Vandry <vandry_at_TZoNE.ORG>
Date: Fri, 12 Apr 2013 21:05:57 -0400

On 2013-04-10 02:22 , Yan Wu wrote:
> Are there some wrong about my usage of CURLOPT_RESOLVE with multi
> interface? Below is my code, I run it on Debian Linux 6, the libcurl is
> version 7.28.

Hi Yan Wu,

I am not sure I fully understand your problem, but I believe I know the
cause.

By default, when each easy handle is added to a multi handle, it
attaches to the multi handle's shared host cache. Any host cache can
only contain one IP address for each hostname, so your two
CURLOPT_RESOLVE option settings end up overwriting one another.

> CURL *ehandle1 = curl_easy_init();
> curl_easy_setopt(ehandle1, CURLOPT_URL, url);
> curl_easy_setopt(ehandle1, CURLOPT_RESOLVE, dns_cache_list1);
>
> CURL* ehandle2 = curl_easy_init();
> curl_easy_setopt(ehandle2, CURLOPT_URL, url);
> curl_easy_setopt(ehandle2, CURLOPT_RESOLVE, dns_cache_list2);

As a workaround, you can assign a separate host cache to each of the
easy handles as follows:

CURL *ehandle1 = curl_easy_init();
CURLSH *sharehandle1 = curl_share_init();
curl_share_setopt(sharehandle1, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS);
curl_easy_setopt(ehandle1, CURLOPT_SHARE, sharehandle1);
curl_easy_setopt(ehandle1, CURLOPT_RESOLVE, dns_cache_list1);

CURL *ehandle2 = curl_easy_init();
CURLSH *sharehandle2 = curl_share_init();
curl_share_setopt(sharehandle2, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS);
curl_easy_setopt(ehandle2, CURLOPT_SHARE, sharehandle2);
curl_easy_setopt(ehandle2, CURLOPT_RESOLVE, dns_cache_list2);

Now when you add the easy handles to the multi handle, cURL will notice
that each of the easy handles already has its own private DNS cache, and
it won't assign the shared multi cache to the handles.

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