c-ares: really lazy init channel

Only initialize the c-ares channel when we start resolving and not
alreads when the application sets `CURLOPT_DNS_SERVERS` and friends.

Creating an ares channel takes considerable time and when we have the
DNS information for a transfer already cached, we do not need it.

Closes #17167
This commit is contained in:
Stefan Eissing 2025-04-24 12:18:33 +02:00 committed by Daniel Stenberg
parent 437c72fbba
commit 7bf576064c
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
4 changed files with 86 additions and 115 deletions

View file

@ -2540,25 +2540,25 @@ static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option,
result = Curl_setstropt(&data->set.str[STRING_DNS_SERVERS], ptr);
if(result)
return result;
return Curl_set_dns_servers(data, data->set.str[STRING_DNS_SERVERS]);
return Curl_async_ares_set_dns_servers(data);
case CURLOPT_DNS_INTERFACE:
result = Curl_setstropt(&data->set.str[STRING_DNS_INTERFACE], ptr);
if(result)
return result;
return Curl_set_dns_interface(data, data->set.str[STRING_DNS_INTERFACE]);
return Curl_async_ares_set_dns_interface(data);
case CURLOPT_DNS_LOCAL_IP4:
result = Curl_setstropt(&data->set.str[STRING_DNS_LOCAL_IP4], ptr);
if(result)
return result;
return Curl_set_dns_local_ip4(data, data->set.str[STRING_DNS_LOCAL_IP4]);
return Curl_async_ares_set_dns_local_ip4(data);
case CURLOPT_DNS_LOCAL_IP6:
result = Curl_setstropt(&data->set.str[STRING_DNS_LOCAL_IP6], ptr);
if(result)
return result;
return Curl_set_dns_local_ip6(data, data->set.str[STRING_DNS_LOCAL_IP6]);
return Curl_async_ares_set_dns_local_ip6(data);
#endif
#ifdef USE_UNIX_SOCKETS