diff options
Diffstat (limited to '')
-rw-r--r-- | src/resolve/resolved-dns-cache.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/resolve/resolved-dns-cache.c b/src/resolve/resolved-dns-cache.c index e90915e..9061908 100644 --- a/src/resolve/resolved-dns-cache.c +++ b/src/resolve/resolved-dns-cache.c @@ -164,8 +164,8 @@ void dns_cache_flush(DnsCache *c) { while ((key = hashmap_first_key(c->by_key))) dns_cache_remove_by_key(c, key); - assert(hashmap_size(c->by_key) == 0); - assert(prioq_size(c->by_expiry) == 0); + assert(hashmap_isempty(c->by_key)); + assert(prioq_isempty(c->by_expiry)); c->by_key = hashmap_free(c->by_key); c->by_expiry = prioq_free(c->by_expiry); @@ -186,7 +186,7 @@ static void dns_cache_make_space(DnsCache *c, unsigned add) { _cleanup_(dns_resource_key_unrefp) DnsResourceKey *key = NULL; DnsCacheItem *i; - if (prioq_size(c->by_expiry) <= 0) + if (prioq_isempty(c->by_expiry)) break; if (prioq_size(c->by_expiry) + add < CACHE_MAX) @@ -243,6 +243,22 @@ void dns_cache_prune(DnsCache *c) { } } +bool dns_cache_expiry_in_one_second(DnsCache *c, usec_t t) { + DnsCacheItem *i; + + assert(c); + + /* Check if any items expire within the next second */ + i = prioq_peek(c->by_expiry); + if (!i) + return false; + + if (i->until <= usec_add(t, USEC_PER_SEC)) + return true; + + return false; +} + static int dns_cache_item_prioq_compare_func(const void *a, const void *b) { const DnsCacheItem *x = a, *y = b; |