asyn resolver code improvements

"asyn" is the internal name under which both c-ares and threaded
resolver operate. Make the naming more consistent. Implement the c-ares
resolver in `asyn-ares.*` and the threaded resolver in `asyn-thrdd.*`.
The common functions are in `asyn-base.c`.

When `CURLRES_ASYNCH` is defined, either of the two is used and
`data->state.async` exists. Members of that struct vary for the selected
implementation, but have the fields `hostname`, `port` and `ip_version`
always present. This are populated when the async resolving starts and
eliminate the need to pass them again when checking on the status and
processing the results of the resolving.

Add a `Curl_resolv_blocking()` to `hostip.h` that relieves FTP and SOCKS
from having to repeat the same code.

`Curl_resolv_check()` remains the function to check for status of
ongoing resolving. Now it also performs internally the check if the
needed DNS entry exists in the dnscache and if so, aborts the asnyc
operation. (libcurl right now does not check for duplicate resolve
attempts. an area for future improvements).

The number of functions in `asyn.h` has been reduced. There were subtle
difference in "cancel()" and "kill()" calls, both replaced by
`Curl_async_shutdown()` now. This changes behaviour for threaded
resolver insofar as the resolving thread is now always joined unless
`data->set.quick_exit` is set. Before this was only done on some code
paths. A future improvement would be a thread pool that keeps a limit
and also could handle joins more gracefully.

DoH, not previously tagged under "asny", has its struct `doh_probes` now
also in `data->state.async`, moved there from `data->req` because it
makes more sense. Further integration of DoH underneath the "asyn"
umbrella seems like a good idea.

Closes #16963
This commit is contained in:
Stefan Eissing 2025-04-11 14:43:45 +02:00 committed by Daniel Stenberg
parent be718daf99
commit 56e40ae6a5
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
30 changed files with 1902 additions and 2134 deletions

View file

@ -538,8 +538,8 @@ static CURLcode multi_done(struct Curl_easy *data,
/* Stop if multi_done() has already been called */
return CURLE_OK;
/* Stop the resolver and free its own resources (but not dns_entry yet). */
Curl_resolver_kill(data);
/* Shut down any ongoing async resolver operation. */
Curl_async_shutdown(data);
/* Cleanup possible redirect junk */
Curl_safefree(data->req.newurl);
@ -2050,35 +2050,12 @@ static CURLMcode state_resolving(struct Curl_multi *multi,
CURLcode *resultp)
{
struct Curl_dns_entry *dns = NULL;
struct connectdata *conn = data->conn;
const char *hostname;
CURLcode result = CURLE_OK;
CURLcode result;
CURLMcode rc = CURLM_OK;
DEBUGASSERT(conn);
#ifndef CURL_DISABLE_PROXY
if(conn->bits.httpproxy)
hostname = conn->http_proxy.host.name;
else
#endif
if(conn->bits.conn_to_host)
hostname = conn->conn_to_host.name;
else
hostname = conn->host.name;
/* check if we have the name resolved by now */
dns = Curl_fetch_addr(data, hostname, conn->primary.remote_port);
if(dns) {
/* Tell a possibly async resolver we no longer need the results. */
Curl_resolver_set_result(data, dns);
result = CURLE_OK;
infof(data, "Hostname '%s' was found in DNS cache", hostname);
}
if(!dns)
result = Curl_resolv_check(data, &dns);
result = Curl_resolv_check(data, &dns);
CURL_TRC_DNS(data, "Curl_resolv_check() -> %d, %s",
result, dns ? "found" : "missing");
/* Update sockets here, because the socket(s) may have been closed and the
application thus needs to be told, even if it is likely that the same
socket(s) will again be used further down. If the name has not yet been