X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-core%2Fmulticast-lookup.c;h=75988bfcd5434c154429f6664f828f7bbcd667f4;hb=e80dfc163e06f9bd9300d096f384bf418ac3062f;hp=641ee4da939a9d8af49a7f3e7efa9e4079230617;hpb=8185ec8431c51946095d3f11e80545e3519f67cf;p=catta diff --git a/avahi-core/multicast-lookup.c b/avahi-core/multicast-lookup.c index 641ee4d..75988bf 100644 --- a/avahi-core/multicast-lookup.c +++ b/avahi-core/multicast-lookup.c @@ -1,18 +1,16 @@ -/* $Id$ */ - /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -23,31 +21,35 @@ #include #endif +#include + #include +#include -#include "server.h" +#include "internal.h" #include "browse.h" #include "socket.h" #include "log.h" #include "hashmap.h" #include "multicast-lookup.h" +#include "rr-util.h" struct AvahiMulticastLookup { AvahiMulticastLookupEngine *engine; int dead; AvahiKey *key, *cname_key; - + AvahiMulticastLookupCallback callback; void *userdata; AvahiIfIndex interface; AvahiProtocol protocol; - + int queriers_added; AvahiTimeEvent *all_for_now_event; - + AVAHI_LLIST_FIELDS(AvahiMulticastLookup, lookups); AVAHI_LLIST_FIELDS(AvahiMulticastLookup, by_key); }; @@ -81,10 +83,10 @@ AvahiMulticastLookup *avahi_multicast_lookup_new( AvahiKey *key, AvahiMulticastLookupCallback callback, void *userdata) { - + AvahiMulticastLookup *l, *t; - struct timeval ctime; - + struct timeval tv; + assert(e); assert(AVAHI_IF_VALID(interface)); assert(AVAHI_PROTO_VALID(protocol)); @@ -109,13 +111,15 @@ AvahiMulticastLookup *avahi_multicast_lookup_new( AVAHI_LLIST_PREPEND(AvahiMulticastLookup, lookups, e->lookups, l); - avahi_querier_add_for_all(e->server, interface, protocol, l->key, &ctime); + avahi_querier_add_for_all(e->server, interface, protocol, l->key, &tv); + l->queriers_added = 1; - /* add a second */ - avahi_timeval_add(&ctime, 1000000); + /* Add a second */ + avahi_timeval_add(&tv, 1000000); + + /* Issue the ALL_FOR_NOW event one second after the querier was initially created */ + l->all_for_now_event = avahi_time_event_new(e->server->time_event_queue, &tv, all_for_now_callback, l); - l->all_for_now_event = avahi_time_event_new(e->server->time_event_queue, &ctime, all_for_now_callback, l); - return l; } @@ -140,7 +144,7 @@ static void lookup_destroy(AvahiMulticastLookup *l) { assert(l); lookup_stop(l); - + t = avahi_hashmap_lookup(l->engine->lookups_by_key, l->key); AVAHI_LLIST_REMOVE(AvahiMulticastLookup, by_key, t, l); if (t) @@ -155,7 +159,7 @@ static void lookup_destroy(AvahiMulticastLookup *l) { if (l->cname_key) avahi_key_unref(l->cname_key); - + avahi_free(l); } @@ -173,13 +177,13 @@ void avahi_multicast_lookup_free(AvahiMulticastLookup *l) { void avahi_multicast_lookup_engine_cleanup(AvahiMulticastLookupEngine *e) { AvahiMulticastLookup *l, *n; assert(e); - + while (e->cleanup_dead) { e->cleanup_dead = 0; - + for (l = e->lookups; l; l = n) { n = l->lookups_next; - + if (l->dead) lookup_destroy(l); } @@ -213,7 +217,7 @@ static void* scan_cache_callback(AvahiCache *c, AvahiKey *pattern, AvahiCacheEnt cbdata->userdata); cbdata->n_found ++; - + return NULL; } @@ -225,12 +229,12 @@ static void scan_interface_callback(AvahiInterfaceMonitor *m, AvahiInterface *i, assert(cbdata); cbdata->interface = i; - + avahi_cache_walk(i->cache, cbdata->key, scan_cache_callback, cbdata); if (cbdata->cname_key) avahi_cache_walk(i->cache, cbdata->cname_key, scan_cache_callback, cbdata); - + cbdata->interface = NULL; } @@ -241,9 +245,9 @@ unsigned avahi_multicast_lookup_engine_scan_cache( AvahiKey *key, AvahiMulticastLookupCallback callback, void *userdata) { - + struct cbdata cbdata; - + assert(e); assert(key); assert(callback); @@ -258,9 +262,9 @@ unsigned avahi_multicast_lookup_engine_scan_cache( cbdata.userdata = userdata; cbdata.interface = NULL; cbdata.n_found = 0; - + avahi_interface_monitor_walk(e->server->monitor, interface, protocol, scan_interface_callback, &cbdata); - + if (cbdata.cname_key) avahi_key_unref(cbdata.cname_key); @@ -269,12 +273,12 @@ unsigned avahi_multicast_lookup_engine_scan_cache( void avahi_multicast_lookup_engine_new_interface(AvahiMulticastLookupEngine *e, AvahiInterface *i) { AvahiMulticastLookup *l; - + assert(e); assert(i); for (l = e->lookups; l; l = l->lookups_next) { - + if (l->dead || !l->callback) continue; @@ -285,7 +289,7 @@ void avahi_multicast_lookup_engine_new_interface(AvahiMulticastLookupEngine *e, void avahi_multicast_lookup_engine_notify(AvahiMulticastLookupEngine *e, AvahiInterface *i, AvahiRecord *record, AvahiBrowserEvent event) { AvahiMulticastLookup *l; - + assert(e); assert(record); assert(i); @@ -307,7 +311,7 @@ void avahi_multicast_lookup_engine_notify(AvahiMulticastLookupEngine *e, AvahiIn if (l->dead || !l->callback) continue; - + if ((key = avahi_key_new_cname(l->key))) { if (avahi_key_equal(record->key, key)) l->callback(e, i->hardware->index, i->protocol, event, AVAHI_LOOKUP_RESULT_MULTICAST, record, l->userdata); @@ -320,9 +324,9 @@ void avahi_multicast_lookup_engine_notify(AvahiMulticastLookupEngine *e, AvahiIn AvahiMulticastLookupEngine *avahi_multicast_lookup_engine_new(AvahiServer *s) { AvahiMulticastLookupEngine *e; - + assert(s); - + e = avahi_new(AvahiMulticastLookupEngine, 1); e->server = s; e->cleanup_dead = 0;