summaryrefslogtreecommitdiffstats
path: root/avahi-core/cache.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2005-06-03 20:27:00 +0000
committerLennart Poettering <lennart@poettering.net>2005-06-03 20:27:00 +0000
commitb6820898d317c29a31f97018ede6da5195d16bfb (patch)
tree0193a8086c95c03abc6d176e62bb903e473247e0 /avahi-core/cache.c
parent3184280a20d54b8f468d0b8d6ff0980b74610ec5 (diff)
* use FIONREAD to minimize allocated buffer size when reading incoming packets
* enforce a cache size limit git-svn-id: file:///home/lennart/svn/public/avahi/trunk@96 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
Diffstat (limited to 'avahi-core/cache.c')
-rw-r--r--avahi-core/cache.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/avahi-core/cache.c b/avahi-core/cache.c
index 433f5a8..8f9ffaf 100644
--- a/avahi-core/cache.c
+++ b/avahi-core/cache.c
@@ -28,6 +28,8 @@
#include "util.h"
#include "cache.h"
+#define AVAHI_MAX_CACHE_ENTRIES 200
+
static void remove_entry(AvahiCache *c, AvahiCacheEntry *e) {
AvahiCacheEntry *t;
@@ -55,6 +57,8 @@ static void remove_entry(AvahiCache *c, AvahiCacheEntry *e) {
avahi_record_unref(e->record);
g_free(e);
+
+ g_assert(c->n_entries-- >= 1);
}
AvahiCache *avahi_cache_new(AvahiServer *server, AvahiInterface *iface) {
@@ -67,6 +71,7 @@ AvahiCache *avahi_cache_new(AvahiServer *server, AvahiInterface *iface) {
c->hash_table = g_hash_table_new((GHashFunc) avahi_key_hash, (GEqualFunc) avahi_key_equal);
AVAHI_LLIST_HEAD_INIT(AvahiCacheEntry, c->entries);
+ c->n_entries = 0;
return c;
}
@@ -76,6 +81,7 @@ void avahi_cache_free(AvahiCache *c) {
while (c->entries)
remove_entry(c, c->entries);
+ g_assert(c->n_entries == 0);
g_hash_table_destroy(c->hash_table);
@@ -293,6 +299,11 @@ void avahi_cache_update(AvahiCache *c, AvahiRecord *r, gboolean cache_flush, con
/* No entry found, therefore we create a new one */
/* g_message("couldn't find matching cache entry"); */
+
+ if (c->n_entries >= AVAHI_MAX_CACHE_ENTRIES)
+ return;
+
+ c->n_entries++;
e = g_new(AvahiCacheEntry, 1);
e->cache = c;