X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-core%2Fcache.c;h=8f9ffafdab41090525a42f347de86ec970c753f7;hb=64dff8088b43bd2f367f35e18bf02e73c8052dec;hp=ec4ee6088e55e1a57a410c3b7f24eaf8f9eab74f;hpb=a29887070855153ac64a3503e2f0004c2056f8e8;p=catta diff --git a/avahi-core/cache.c b/avahi-core/cache.c index ec4ee60..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; @@ -50,11 +52,13 @@ static void remove_entry(AvahiCache *c, AvahiCacheEntry *e) { if (e->time_event) avahi_time_event_queue_remove(c->server->time_event_queue, e->time_event); - avahi_resolver_notify(c->server, c->interface, e->record, AVAHI_BROWSER_REMOVE); + avahi_browser_notify(c->server, c->interface, e->record, AVAHI_BROWSER_REMOVE); 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); @@ -182,7 +188,7 @@ static void elapse_func(AvahiTimeEvent *t, void *userdata) { g_assert(percent > 0); /* Request a cache update, if we are subscribed to this entry */ - if (avahi_is_subscribed(e->cache->server, e->record->key)) { + if (avahi_is_subscribed(e->cache->server, e->cache->interface, e->record->key)) { /* g_message("Requesting cache entry update at %i%%.", percent); */ avahi_interface_post_query(e->cache->interface, e->record->key, TRUE); } @@ -230,7 +236,7 @@ static void expire_in_one_second(AvahiCache *c, AvahiCacheEntry *e) { update_time_event(c, e); } -void avahi_cache_update(AvahiCache *c, AvahiRecord *r, gboolean unique, const AvahiAddress *a) { +void avahi_cache_update(AvahiCache *c, AvahiRecord *r, gboolean cache_flush, const AvahiAddress *a) { /* gchar *txt; */ g_assert(c); @@ -257,7 +263,7 @@ void avahi_cache_update(AvahiCache *c, AvahiRecord *r, gboolean unique, const Av if ((first = avahi_cache_lookup_key(c, r->key))) { - if (unique) { + if (cache_flush) { /* For unique entries drop all entries older than one second */ for (e = first; e; e = e->by_key_next) { @@ -288,11 +294,16 @@ void avahi_cache_update(AvahiCache *c, AvahiRecord *r, gboolean unique, const Av /* Update the record */ avahi_record_unref(e->record); e->record = avahi_record_ref(r); - + } else { /* 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; @@ -307,13 +318,14 @@ void avahi_cache_update(AvahiCache *c, AvahiRecord *r, gboolean unique, const Av AVAHI_LLIST_PREPEND(AvahiCacheEntry, entry, c->entries, e); /* Notify subscribers */ - avahi_resolver_notify(c->server, c->interface, e->record, AVAHI_BROWSER_NEW); + avahi_browser_notify(c->server, c->interface, e->record, AVAHI_BROWSER_NEW); } e->origin = *a; e->timestamp = now; next_expiry(c, e, 80); e->state = AVAHI_CACHE_VALID; + e->cache_flush = cache_flush; } }