4 This file is part of avahi.
6 avahi is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 avahi is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
14 Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with avahi; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
36 static const AvahiPoll *api = NULL;
39 #include "simple-watch.h"
40 static AvahiSimplePoll *simple_poll = NULL;
42 #include "thread-watch.h"
43 static AvahiThreadedPoll *threaded_poll = NULL;
46 static void callback(AvahiWatch *w, int fd, AvahiWatchEvent event, AVAHI_GCC_UNUSED void *userdata) {
48 if (event & AVAHI_WATCH_IN) {
52 if ((r = read(fd, &c, 1)) <= 0) {
53 fprintf(stderr, "read() failed: %s\n", r < 0 ? strerror(errno) : "EOF");
58 printf("Read: %c\n", c >= 32 && c < 127 ? c : '.');
62 static void wakeup(AvahiTimeout *t, AVAHI_GCC_UNUSED void *userdata) {
66 printf("Wakeup #%i\n", i++);
70 avahi_simple_poll_quit(simple_poll);
72 avahi_threaded_poll_quit(threaded_poll);
75 avahi_elapse_time(&tv, 1000, 0);
76 api->timeout_update(t, &tv);
80 int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
84 simple_poll = avahi_simple_poll_new();
86 api = avahi_simple_poll_get(simple_poll);
89 threaded_poll = avahi_threaded_poll_new();
90 assert(threaded_poll);
91 api = avahi_threaded_poll_get(threaded_poll);
95 api->watch_new(api, 0, AVAHI_WATCH_IN, callback, NULL);
97 avahi_elapse_time(&tv, 1000, 0);
98 api->timeout_new(api, &tv, wakeup, NULL);
102 avahi_simple_poll_loop(simple_poll);
103 avahi_simple_poll_free(simple_poll);
106 avahi_threaded_poll_start(threaded_poll);
108 fprintf(stderr, "Now doing some stupid stuff ...\n");
110 fprintf(stderr, "... stupid stuff is done.\n");
112 avahi_threaded_poll_free(threaded_poll);