mirror of
https://github.com/curl/curl.git
synced 2026-04-15 05:01:42 +03:00
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:
parent
be718daf99
commit
56e40ae6a5
30 changed files with 1902 additions and 2134 deletions
|
|
@ -159,31 +159,23 @@ void Curl_httpsrr_cleanup(struct Curl_https_rrinfo *rrinfo)
|
|||
|
||||
static CURLcode httpsrr_opt(struct Curl_easy *data,
|
||||
const ares_dns_rr_t *rr,
|
||||
ares_dns_rr_key_t key, size_t idx)
|
||||
ares_dns_rr_key_t key, size_t idx,
|
||||
struct Curl_https_rrinfo *hinfo)
|
||||
{
|
||||
size_t len = 0;
|
||||
const unsigned char *val = NULL;
|
||||
unsigned short code;
|
||||
struct thread_data *res = &data->state.async.thdata;
|
||||
struct Curl_https_rrinfo *hi = &res->hinfo;
|
||||
size_t len = 0;
|
||||
|
||||
code = ares_dns_rr_get_opt(rr, key, idx, &val, &len);
|
||||
return Curl_httpsrr_set(data, hi, code, val, len);
|
||||
return Curl_httpsrr_set(data, hinfo, code, val, len);
|
||||
}
|
||||
|
||||
void Curl_dnsrec_done_cb(void *arg, ares_status_t status,
|
||||
size_t timeouts,
|
||||
const ares_dns_record_t *dnsrec)
|
||||
CURLcode Curl_httpsrr_from_ares(struct Curl_easy *data,
|
||||
const ares_dns_record_t *dnsrec,
|
||||
struct Curl_https_rrinfo *hinfo)
|
||||
{
|
||||
struct Curl_easy *data = arg;
|
||||
CURLcode result = CURLE_OK;
|
||||
size_t i;
|
||||
struct thread_data *res = &data->state.async.thdata;
|
||||
|
||||
res->num_pending--;
|
||||
(void)timeouts;
|
||||
if((ARES_SUCCESS != status) || !dnsrec)
|
||||
return;
|
||||
|
||||
for(i = 0; i < ares_dns_record_rr_cnt(dnsrec, ARES_SECTION_ANSWER); i++) {
|
||||
const char *target;
|
||||
|
|
@ -196,24 +188,24 @@ void Curl_dnsrec_done_cb(void *arg, ares_status_t status,
|
|||
is in ServiceMode */
|
||||
target = ares_dns_rr_get_str(rr, ARES_RR_HTTPS_TARGET);
|
||||
if(target && target[0]) {
|
||||
res->hinfo.target = strdup(target);
|
||||
if(!res->hinfo.target) {
|
||||
hinfo->target = strdup(target);
|
||||
if(!hinfo->target) {
|
||||
result = CURLE_OUT_OF_MEMORY;
|
||||
goto out;
|
||||
}
|
||||
CURL_TRC_DNS(data, "HTTPS RR target: %s", res->hinfo.target);
|
||||
CURL_TRC_DNS(data, "HTTPS RR target: %s", hinfo->target);
|
||||
}
|
||||
CURL_TRC_DNS(data, "HTTPS RR priority: %u",
|
||||
ares_dns_rr_get_u16(rr, ARES_RR_HTTPS_PRIORITY));
|
||||
for(opt = 0; opt < ares_dns_rr_get_opt_cnt(rr, ARES_RR_HTTPS_PARAMS);
|
||||
opt++) {
|
||||
result = httpsrr_opt(data, rr, ARES_RR_HTTPS_PARAMS, opt);
|
||||
result = httpsrr_opt(data, rr, ARES_RR_HTTPS_PARAMS, opt, hinfo);
|
||||
if(result)
|
||||
break;
|
||||
}
|
||||
}
|
||||
out:
|
||||
res->result = result;
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif /* USE_ARES */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue