[Net] Simplify IP resolution code, fix caching.

First, we should not insert into cache if the hostname resolution has
failed (as it might be a temporary internet issue), second, the async
resolver should also properly insert into cache.

Took the chance to remove some duplicate code with critical section in
it at the cost of little performance when calling the blocking
resolve_hostname function.

(cherry picked from commit 49297d937c)
This commit is contained in:
Fabio Alessandrelli 2022-01-29 01:33:29 +01:00 committed by Rémi Verschelde
parent c25365d5ff
commit aa3ef20fcb
No known key found for this signature in database
GPG key ID: C3336907360768E1
2 changed files with 13 additions and 31 deletions

View file

@ -115,7 +115,7 @@ void IP_Unix::_resolve_hostname(List<IP_Address> &r_addresses, const String &p_h
continue;
}
IP_Address ip = _sockaddr2ip(next->ai_addr);
if (!r_addresses.find(ip)) {
if (ip.is_valid() && !r_addresses.find(ip)) {
r_addresses.push_back(ip);
}
next = next->ai_next;