Пример #1
0
static AvahiResponseJob* find_suppressed_job(AvahiResponseScheduler *s, AvahiRecord *record, const AvahiAddress *querier) {
    AvahiResponseJob *rj;
    
    assert(s);
    assert(record);
    assert(querier);

    for (rj = s->suppressed; rj; rj = rj->jobs_next) {
        assert(rj->state == AVAHI_SUPPRESSED);
        assert(rj->querier_valid);
        
        if (avahi_record_equal_no_ttl(rj->record, record) &&
            avahi_address_cmp(&rj->querier, querier) == 0) {
            /* Check whether this entry is outdated */

            if (avahi_age(&rj->delivery) > AVAHI_RESPONSE_SUPPRESS_MSEC*1000) {
                /* it is outdated, so let's remove it */
                job_free(s, rj);
                return NULL;
            }

            return rj;
        }
    }

    return NULL;
}
Пример #2
0
static AvahiResponseJob* find_history_job(AvahiResponseScheduler *s, AvahiRecord *record) {
    AvahiResponseJob *rj;
    
    assert(s);
    assert(record);

    for (rj = s->history; rj; rj = rj->jobs_next) {
        assert(rj->state == AVAHI_DONE);

        if (avahi_record_equal_no_ttl(rj->record, record)) {
            /* Check whether this entry is outdated */

/*             avahi_log_debug("history age: %u", (unsigned) (avahi_age(&rj->delivery)/1000)); */
            
            if (avahi_age(&rj->delivery)/1000 > AVAHI_RESPONSE_HISTORY_MSEC) {
                /* it is outdated, so let's remove it */
                job_free(s, rj);
                return NULL;
            }
                
            return rj;
        }
    }

    return NULL;
}
Пример #3
0
void avahi_s_entry_group_change_state(AvahiSEntryGroup *g, AvahiEntryGroupState state) {
    assert(g);

    if (g->state == state)
        return;

    assert(state <= AVAHI_ENTRY_GROUP_COLLISION);

    if (g->state == AVAHI_ENTRY_GROUP_ESTABLISHED) {

        /* If the entry group was established for a time longer then
         * 5s, reset the establishment trial counter */
        
        if (avahi_age(&g->established_at) > 5000000)
            g->n_register_try = 0;
    } else if (g->state == AVAHI_ENTRY_GROUP_REGISTERING) {
        if (g->register_time_event) {
            avahi_time_event_free(g->register_time_event);
            g->register_time_event = NULL;
        }
    }
    
    if (state == AVAHI_ENTRY_GROUP_ESTABLISHED)

        /* If the entry group is now established, remember the time
         * this happened */
        
        gettimeofday(&g->established_at, NULL);
    
    g->state = state;
    
    if (g->callback)
        g->callback(g->server, g, state, g->userdata);
}
Пример #4
0
static void avahi_set_timer(AvahiTimeout *t, const struct timeval *tv)
{
	if (tv)
	{
		/*struct timeval now;
		gettimeofday(&now, NULL);*/
		AvahiUsec usec = (- avahi_age(tv));
		if (usec < 0)
			usec = 0;
		t->timer->start((usec + 999) / 1000, true);
	}
}
Пример #5
0
int avahi_simple_poll_dispatch(AvahiSimplePoll *s) {
    AvahiTimeout *next_timeout;
    AvahiWatch *w;

    assert(s);
    assert(s->state == STATE_RAN);
    s->state = STATE_DISPATCHING;

    /* We execute only on callback in every iteration */

    /* Check whether the wakeup time has been reached now */
    if ((next_timeout = find_next_timeout(s))) {

        if (next_timeout->expiry.tv_sec == 0 && next_timeout->expiry.tv_usec == 0) {

            /* Just a shortcut so that we don't need to call gettimeofday() */
            timeout_callback(next_timeout);
            goto finish;
        }

        if (avahi_age(&next_timeout->expiry) >= 0) {

            /* Timeout elapsed */
            timeout_callback(next_timeout);
            goto finish;
        }
    }

    /* Look for some kind of I/O event */
    for (w = s->watches; w; w = w->watches_next) {

        if (w->dead)
            continue;

        assert(w->idx >= 0);
        assert(w->idx < s->n_pollfds);

        if (s->pollfds[w->idx].revents != 0) {
            w->callback(w, w->pollfd.fd, s->pollfds[w->idx].revents, w->userdata);
            goto finish;
        }
    }

finish:

    s->state = STATE_DISPATCHED;
    return 0;
}
Пример #6
0
static AvahiQueryJob* find_history_job(AvahiQueryScheduler *s, AvahiKey *key) {
    AvahiQueryJob *qj;

    assert(s);
    assert(key);

    for (qj = s->history; qj; qj = qj->jobs_next) {
        assert(qj->done);

        if (avahi_key_equal(qj->key, key)) {
            /* Check whether this entry is outdated */

            if (avahi_age(&qj->delivery) > AVAHI_QUERY_HISTORY_MSEC*1000) {
                /* it is outdated, so let's remove it */
                job_free(s, qj);
                return NULL;
            }

            return qj;
        }
    }

    return NULL;
}
Пример #7
0
static AvahiProbeJob* find_history_job(AvahiProbeScheduler *s, AvahiRecord *record) {
    AvahiProbeJob *pj;
    
    assert(s);
    assert(record);

    for (pj = s->history; pj; pj = pj->jobs_next) {
        assert(pj->done);

        if (avahi_record_equal_no_ttl(pj->record, record)) {
            /* Check whether this entry is outdated */

            if (avahi_age(&pj->delivery) > AVAHI_PROBE_HISTORY_MSEC*1000) {
                /* it is outdated, so let's remove it */
                job_free(s, pj);
                return NULL;
            }
                
            return pj;
        }
    }

    return NULL;
}