Lines Matching full:cache
12 static void dns_cache_clean(struct dns_cache const *cache);
14 int dns_cache_flush(struct dns_cache *cache) in dns_cache_flush() argument
16 k_mutex_lock(cache->lock, K_FOREVER); in dns_cache_flush()
17 for (size_t i = 0; i < cache->size; i++) { in dns_cache_flush()
18 cache->entries[i].in_use = false; in dns_cache_flush()
20 k_mutex_unlock(cache->lock); in dns_cache_flush()
25 int dns_cache_add(struct dns_cache *cache, char const *query, struct dns_addrinfo const *addrinfo, in dns_cache_add() argument
32 if (cache == NULL || query == NULL || addrinfo == NULL || ttl == 0) { in dns_cache_add()
43 k_mutex_lock(cache->lock, K_FOREVER); in dns_cache_add()
47 dns_cache_clean(cache); in dns_cache_add()
49 for (size_t i = 0; i < cache->size; i++) { in dns_cache_add()
50 if (!cache->entries[i].in_use) { in dns_cache_add()
54 } else if (sys_timepoint_cmp(closest_to_expiry, cache->entries[i].expiry) > 0) { in dns_cache_add()
56 closest_to_expiry = cache->entries[i].expiry; in dns_cache_add()
61 NET_DBG("Overwrite \"%s\"", cache->entries[index_to_replace].query); in dns_cache_add()
64 strncpy(cache->entries[index_to_replace].query, query, in dns_cache_add()
66 cache->entries[index_to_replace].data = *addrinfo; in dns_cache_add()
67 cache->entries[index_to_replace].expiry = sys_timepoint_calc(K_SECONDS(ttl)); in dns_cache_add()
68 cache->entries[index_to_replace].in_use = true; in dns_cache_add()
70 k_mutex_unlock(cache->lock); in dns_cache_add()
75 int dns_cache_remove(struct dns_cache *cache, char const *query) in dns_cache_remove() argument
85 k_mutex_lock(cache->lock, K_FOREVER); in dns_cache_remove()
87 dns_cache_clean(cache); in dns_cache_remove()
89 for (size_t i = 0; i < cache->size; i++) { in dns_cache_remove()
90 if (cache->entries[i].in_use && strcmp(cache->entries[i].query, query) == 0) { in dns_cache_remove()
91 cache->entries[i].in_use = false; in dns_cache_remove()
95 k_mutex_unlock(cache->lock); in dns_cache_remove()
100 int dns_cache_find(struct dns_cache const *cache, const char *query, struct dns_addrinfo *addrinfo, in dns_cache_find() argument
106 if (cache == NULL || query == NULL || addrinfo == NULL || addrinfo_array_len <= 0) { in dns_cache_find()
116 k_mutex_lock(cache->lock, K_FOREVER); in dns_cache_find()
118 dns_cache_clean(cache); in dns_cache_find()
120 for (size_t i = 0; i < cache->size; i++) { in dns_cache_find()
121 if (!cache->entries[i].in_use) { in dns_cache_find()
124 if (strcmp(cache->entries[i].query, query) != 0) { in dns_cache_find()
131 addrinfo[found] = cache->entries[i].data; in dns_cache_find()
137 k_mutex_unlock(cache->lock); in dns_cache_find()
150 static void dns_cache_clean(struct dns_cache const *cache) in dns_cache_clean() argument
152 for (size_t i = 0; i < cache->size; i++) { in dns_cache_clean()
153 if (!cache->entries[i].in_use) { in dns_cache_clean()
157 if (sys_timepoint_expired(cache->entries[i].expiry)) { in dns_cache_clean()
158 NET_DBG("Remove \"%s\"", cache->entries[i].query); in dns_cache_clean()
159 cache->entries[i].in_use = false; in dns_cache_clean()