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 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.
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
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
* entries) most of the time, but this might be a wrong
* assumption, especially on setups where traffic reflection is
* involved. */
* entries) most of the time, but this might be a wrong
* assumption, especially on setups where traffic reflection is
* involved. */
AVAHI_LLIST_PREPEND(AvahiQueryJob, jobs, s->history, qj);
else
AVAHI_LLIST_PREPEND(AvahiQueryJob, jobs, s->jobs, qj);
AVAHI_LLIST_PREPEND(AvahiQueryJob, jobs, s->history, qj);
else
AVAHI_LLIST_PREPEND(AvahiQueryJob, jobs, s->jobs, qj);
AVAHI_LLIST_HEAD_INIT(AvahiQueryJob, s->jobs);
AVAHI_LLIST_HEAD_INIT(AvahiQueryJob, s->history);
AVAHI_LLIST_HEAD_INIT(AvahiKnownAnswer, s->known_answers);
AVAHI_LLIST_HEAD_INIT(AvahiQueryJob, s->jobs);
AVAHI_LLIST_HEAD_INIT(AvahiQueryJob, s->history);
AVAHI_LLIST_HEAD_INIT(AvahiKnownAnswer, s->known_answers);
static void* known_answer_walk_callback(AvahiCache *c, AvahiKey *pattern, AvahiCacheEntry *e, void* userdata) {
AvahiQueryScheduler *s = userdata;
AvahiKnownAnswer *ka;
static void* known_answer_walk_callback(AvahiCache *c, AvahiKey *pattern, AvahiCacheEntry *e, void* userdata) {
AvahiQueryScheduler *s = userdata;
AvahiKnownAnswer *ka;
if (!(ka = avahi_new0(AvahiKnownAnswer, 1))) {
avahi_log_error(__FILE__": Out of memory");
return NULL;
}
if (!(ka = avahi_new0(AvahiKnownAnswer, 1))) {
avahi_log_error(__FILE__": Out of memory");
return NULL;
}
/* Add all matching known answers to the list */
avahi_cache_walk(s->interface->cache, qj->key, known_answer_walk_callback, s);
/* Add all matching known answers to the list */
avahi_cache_walk(s->interface->cache, qj->key, known_answer_walk_callback, s);
avahi_dns_packet_set_field(p, AVAHI_DNS_FIELD_ANCOUNT, n);
avahi_interface_send_packet(s->interface, p);
avahi_dns_packet_free(p);
avahi_dns_packet_set_field(p, AVAHI_DNS_FIELD_ANCOUNT, n);
avahi_interface_send_packet(s->interface, p);
avahi_dns_packet_free(p);
b = packet_add_query_job(s, p, qj);
assert(b); /* An query must always fit in */
n = 1;
b = packet_add_query_job(s, p, qj);
assert(b); /* An query must always fit in */
n = 1;
int avahi_query_scheduler_post(AvahiQueryScheduler *s, AvahiKey *key, int immediately, unsigned *ret_id) {
struct timeval tv;
AvahiQueryJob *qj;
int avahi_query_scheduler_post(AvahiQueryScheduler *s, AvahiKey *key, int immediately, unsigned *ret_id) {
struct timeval tv;
AvahiQueryJob *qj;
avahi_elapse_time(&tv, immediately ? 0 : AVAHI_QUERY_DEFER_MSEC, 0);
if ((qj = find_scheduled_job(s, key))) {
avahi_elapse_time(&tv, immediately ? 0 : AVAHI_QUERY_DEFER_MSEC, 0);
if ((qj = find_scheduled_job(s, key))) {
qj->delivery = tv;
qj->time_event = avahi_time_event_new(s->time_event_queue, &qj->delivery, elapse_callback, qj);
}
if (ret_id)
*ret_id = qj->id;
qj->delivery = tv;
qj->time_event = avahi_time_event_new(s->time_event_queue, &qj->delivery, elapse_callback, qj);
}
if (ret_id)
*ret_id = qj->id;
if (!(qj = find_history_job(s, key)))
if (!(qj = job_new(s, key, 1)))
return; /* OOM */
if (!(qj = find_history_job(s, key)))
if (!(qj = job_new(s, key, 1)))
return; /* OOM */
gettimeofday(&qj->delivery, NULL);
job_set_elapse_time(s, qj, AVAHI_QUERY_HISTORY_MSEC, 0);
}
int avahi_query_scheduler_withdraw_by_id(AvahiQueryScheduler *s, unsigned id) {
AvahiQueryJob *qj;
gettimeofday(&qj->delivery, NULL);
job_set_elapse_time(s, qj, AVAHI_QUERY_HISTORY_MSEC, 0);
}
int avahi_query_scheduler_withdraw_by_id(AvahiQueryScheduler *s, unsigned id) {
AvahiQueryJob *qj;
* case since there should exist only one querier per
* key, but there are exceptions, notably reflected
* traffic.) */
* case since there should exist only one querier per
* key, but there are exceptions, notably reflected
* traffic.) */