diff options
| author | Elliott Hughes <enh@google.com> | 2012-05-07 13:59:59 -0700 |
|---|---|---|
| committer | Android Git Automerger <android-git-automerger@android.com> | 2012-05-07 13:59:59 -0700 |
| commit | 53daf4757d36522c132006e2f74ed81bb4ed717a (patch) | |
| tree | e1d4b0d32ab813001db4c0851b7d068b0679030c /libc/netbsd/resolv/res_cache.c | |
| parent | e636e1f2c17d7097b6638cb4ae2b4857765b502d (diff) | |
| parent | 73a6566da337db50cfc73c369d774ac1905a30c2 (diff) | |
| download | bionic-53daf4757d36522c132006e2f74ed81bb4ed717a.zip bionic-53daf4757d36522c132006e2f74ed81bb4ed717a.tar.gz bionic-53daf4757d36522c132006e2f74ed81bb4ed717a.tar.bz2 | |
am 73a6566d: Merge "Remove expired dns cache entries before removing oldest"
* commit '73a6566da337db50cfc73c369d774ac1905a30c2':
Remove expired dns cache entries before removing oldest
Diffstat (limited to 'libc/netbsd/resolv/res_cache.c')
| -rw-r--r-- | libc/netbsd/resolv/res_cache.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/libc/netbsd/resolv/res_cache.c b/libc/netbsd/resolv/res_cache.c index 9ae627c..0bb2f23 100644 --- a/libc/netbsd/resolv/res_cache.c +++ b/libc/netbsd/resolv/res_cache.c @@ -1433,6 +1433,27 @@ _cache_remove_oldest( Cache* cache ) _cache_remove_p(cache, lookup); } +/* Remove all expired entries from the hash table. + */ +static void _cache_remove_expired(Cache* cache) { + Entry* e; + time_t now = _time_now(); + + for (e = cache->mru_list.mru_next; e != &cache->mru_list;) { + // Entry is old, remove + if (now >= e->expires) { + Entry** lookup = _cache_lookup_p(cache, e); + if (*lookup == NULL) { /* should not happen */ + XLOG("%s: ENTRY NOT IN HTABLE ?", __FUNCTION__); + return; + } + e = e->mru_next; + _cache_remove_p(cache, lookup); + } else { + e = e->mru_next; + } + } +} ResolvCacheStatus _resolv_cache_lookup( struct resolv_cache* cache, @@ -1547,7 +1568,10 @@ _resolv_cache_add( struct resolv_cache* cache, } if (cache->num_entries >= cache->max_entries) { - _cache_remove_oldest(cache); + _cache_remove_expired(cache); + if (cache->num_entries >= cache->max_entries) { + _cache_remove_oldest(cache); + } /* need to lookup again */ lookup = _cache_lookup_p(cache, key); e = *lookup; |
