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
static AvahiWatch* watch_new(const AvahiPoll *api, int fd, AvahiWatchEvent event, AvahiWatchCallback callback, void *userdata) {
AvahiWatch *w;
AvahiSimplePoll *s;
static AvahiWatch* watch_new(const AvahiPoll *api, int fd, AvahiWatchEvent event, AvahiWatchCallback callback, void *userdata) {
AvahiWatch *w;
AvahiSimplePoll *s;
/* If there is a background thread running the poll() for us, tell it to exit the poll() */
avahi_simple_poll_wakeup(s);
/* If there is a background thread running the poll() for us, tell it to exit the poll() */
avahi_simple_poll_wakeup(s);
/* If there is a background thread running the poll() for us, tell it to exit the poll() */
avahi_simple_poll_wakeup(w->simple_poll);
/* If there is a background thread running the poll() for us, tell it to exit the poll() */
avahi_simple_poll_wakeup(w->simple_poll);
static AvahiTimeout* timeout_new(const AvahiPoll *api, const struct timeval *tv, AvahiTimeoutCallback callback, void *userdata) {
AvahiTimeout *t;
AvahiSimplePoll *s;
static AvahiTimeout* timeout_new(const AvahiPoll *api, const struct timeval *tv, AvahiTimeoutCallback callback, void *userdata) {
AvahiTimeout *t;
AvahiSimplePoll *s;
/* If there is a background thread running the poll() for us, tell it to exit the poll() */
avahi_simple_poll_wakeup(s);
/* If there is a background thread running the poll() for us, tell it to exit the poll() */
avahi_simple_poll_wakeup(s);
/* If there is a background thread running the poll() for us, tell it to exit the poll() */
avahi_simple_poll_wakeup(t->simple_poll);
/* If there is a background thread running the poll() for us, tell it to exit the poll() */
avahi_simple_poll_wakeup(t->simple_poll);
s->api.timeout_new = timeout_new;
s->api.timeout_free = timeout_free;
s->api.timeout_update = timeout_update;
s->api.timeout_new = timeout_new;
s->api.timeout_free = timeout_free;
s->api.timeout_update = timeout_update;
avahi_simple_poll_set_func(s, NULL, NULL);
AVAHI_LLIST_HEAD_INIT(AvahiWatch, s->watches);
avahi_simple_poll_set_func(s, NULL, NULL);
AVAHI_LLIST_HEAD_INIT(AvahiWatch, s->watches);
s->pollfds[0].fd = s->wakeup_pipe[0];
s->pollfds[0].events = POLLIN;
s->pollfds[0].revents = 0;
idx = 1;
s->pollfds[0].fd = s->wakeup_pipe[0];
s->pollfds[0].events = POLLIN;
s->pollfds[0].revents = 0;
idx = 1;
int avahi_simple_poll_prepare(AvahiSimplePoll *s, int timeout) {
AvahiTimeout *next_timeout;
int avahi_simple_poll_prepare(AvahiSimplePoll *s, int timeout) {
AvahiTimeout *next_timeout;
assert(s);
assert(s->state == STATE_INIT || s->state == STATE_DISPATCHED || s->state == STATE_FAILURE);
s->state = STATE_PREPARING;
assert(s);
assert(s->state == STATE_INIT || s->state == STATE_DISPATCHED || s->state == STATE_FAILURE);
s->state = STATE_PREPARING;
gettimeofday(&now, NULL);
usec = avahi_timeval_diff(&next_timeout->expiry, &now);
gettimeofday(&now, NULL);
usec = avahi_timeval_diff(&next_timeout->expiry, &now);
int avahi_simple_poll_run(AvahiSimplePoll *s) {
assert(s);
assert(s->state == STATE_PREPARED || s->state == STATE_FAILURE);
int avahi_simple_poll_run(AvahiSimplePoll *s) {
assert(s);
assert(s->state == STATE_PREPARED || s->state == STATE_FAILURE);
if (s->poll_func(s->pollfds, s->n_pollfds, s->prepared_timeout, s->poll_func_userdata) < 0) {
if (s->poll_func(s->pollfds, s->n_pollfds, s->prepared_timeout, s->poll_func_userdata) < 0) {
/* Check whether the wakeup time has been reached now */
if ((next_timeout = find_next_timeout(s))) {
/* 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 (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 (s->pollfds[w->idx].revents != 0) {
w->callback(w, w->pollfd.fd, s->pollfds[w->idx].revents, w->userdata);
goto finish;
if (s->pollfds[w->idx].revents != 0) {
w->callback(w, w->pollfd.fd, s->pollfds[w->idx].revents, w->userdata);
goto finish;
for (;;)
if ((r = avahi_simple_poll_iterate(s, -1)) != 0)
if (r >= 0 || errno != EINTR)
for (;;)
if ((r = avahi_simple_poll_iterate(s, -1)) != 0)
if (r >= 0 || errno != EINTR)