+void avahi_simple_poll_wakeup(AvahiSimplePoll *s) {
+ char c = 'W';
+ assert(s);
+
+ write(s->wakeup_pipe[1], &c, sizeof(c));
+ s->wakeup_issued = 1;
+}
+
+static void clear_wakeup(AvahiSimplePoll *s) {
+ char c[10]; /* Read ten at a time */
+
+ if (!s->wakeup_issued)
+ return;
+
+ s->wakeup_issued = 0;
+
+ for(;;)
+ if (read(s->wakeup_pipe[0], &c, sizeof(c)) != sizeof(c))
+ break;
+}
+
+static int set_nonblock(int fd) {
+ int n;
+
+ assert(fd >= 0);
+
+ if ((n = fcntl(fd, F_GETFL)) < 0)
+ return -1;
+
+ if (n & O_NONBLOCK)
+ return 0;
+
+ return fcntl(fd, F_SETFL, n|O_NONBLOCK);
+}
+