hostip: do DNS cache pruning in milliseconds

Instead of using integer seconds. Also: if the cache contains over
30,000 entries after first pruning, it makes anoter round and removes
all entries that are older than half the age of the oldest entry until
it goes below 30,000.

Closes #18160
This commit is contained in:
Daniel Stenberg 2025-08-04 14:15:03 +02:00
parent be71475b13
commit 854b0e230c
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
6 changed files with 51 additions and 45 deletions

View file

@ -868,10 +868,12 @@ static CURLcode setopt_long(struct Curl_easy *data, CURLoption option,
case CURLOPT_DNS_CACHE_TIMEOUT:
if(arg < -1)
return CURLE_BAD_FUNCTION_ARGUMENT;
else if(arg > INT_MAX)
arg = INT_MAX;
else if(arg > INT_MAX/1000)
arg = INT_MAX/1000;
s->dns_cache_timeout = (int)arg;
if(arg > 0)
arg *= 1000;
s->dns_cache_timeout_ms = (int)arg;
break;
case CURLOPT_CA_CACHE_TIMEOUT:
if(Curl_ssl_supports(data, SSLSUPP_CA_CACHE)) {