dnscache: slight refactoring

Slight refactoring around dnscache, e.g. hostcache

- eliminate `data->state.hostcache`. Always look up
  relevant dnscache at share/multi.
- unify naming to "dnscache", replacing "hostcache"
- use `struct Curl_dnscache`, even though it just
  contains a `Curl_hash` for now.
- add `Curl_dnscache_destroy()` for cleanup in
  share/multi.

Closes #16941
This commit is contained in:
Stefan Eissing 2025-04-03 13:11:32 +02:00 committed by Daniel Stenberg
parent 6140a574de
commit 01e76702ac
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
14 changed files with 217 additions and 255 deletions

View file

@ -41,7 +41,7 @@
#include "memdebug.h" /* LAST include file */
static struct Curl_easy *testdata;
static struct Curl_hash hp;
static struct Curl_dnscache hp;
static char *data_key;
static struct Curl_dns_entry *data_node;
@ -53,7 +53,7 @@ static CURLcode unit_setup(void)
return CURLE_OUT_OF_MEMORY;
}
Curl_init_dnscache(&hp, 7);
Curl_dnscache_init(&hp, 7);
return CURLE_OK;
}
@ -64,7 +64,7 @@ static void unit_stop(void)
free(data_node);
}
free(data_key);
Curl_hash_destroy(&hp);
Curl_dnscache_destroy(&hp);
curl_easy_cleanup(testdata);
curl_global_cleanup();
@ -122,7 +122,7 @@ UNITTEST_START
key_len = strlen(data_key);
data_node->refcount = 1; /* hash will hold the reference */
nodep = Curl_hash_add(&hp, data_key, key_len + 1, data_node);
nodep = Curl_hash_add(&hp.entries, data_key, key_len + 1, data_node);
abort_unless(nodep, "insertion into hash failed");
/* Freeing will now be done by Curl_hash_destroy */
data_node = NULL;

View file

@ -139,7 +139,8 @@ UNITTEST_START
entry_id = (void *)aprintf("%s:%d", tests[i].host, tests[i].port);
if(!entry_id)
goto error;
dns = Curl_hash_pick(easy->dns.hostcache, entry_id, strlen(entry_id) + 1);
dns = Curl_hash_pick(&multi->dnscache.entries,
entry_id, strlen(entry_id) + 1);
free(entry_id);
entry_id = NULL;

View file

@ -141,7 +141,8 @@ UNITTEST_START
if(!entry_id)
goto error;
dns = Curl_hash_pick(easy->dns.hostcache, entry_id, strlen(entry_id) + 1);
dns = Curl_hash_pick(&multi->dnscache.entries,
entry_id, strlen(entry_id) + 1);
free(entry_id);
entry_id = NULL;