6 #include <talloc/talloc.h>
17 static struct waiter *waiters;
20 struct waiter *waiter_register(int fd, int events,
21 waiter_cb callback, void *arg)
23 struct waiter *waiter;
27 waiters = talloc_realloc(NULL, waiters, struct waiter, n_waiters);
28 waiter = &waiters[n_waiters - 1];
31 waiter->events = events;
32 waiter->callback = callback;
38 void waiter_remove(struct waiter *waiter)
43 assert(i >= 0 && i < n_waiters);
46 memmove(&waiters[i], &waiters[i+1], n_waiters - i);
48 waiters = talloc_realloc(NULL, waiters, struct waiter, n_waiters);
53 static struct pollfd *pollfds;
57 if (n_waiters != n_pollfds) {
58 pollfds = talloc_realloc(NULL, pollfds,
59 struct pollfd, n_waiters);
60 n_pollfds = n_waiters;
63 for (i = 0; i < n_waiters; i++) {
64 pollfds[i].fd = waiters[i].fd;
65 pollfds[i].events = waiters[i].events;
66 pollfds[i].revents = 0;
69 rc = poll(pollfds, n_waiters, -1);
74 for (i = 0; i < n_waiters; i++) {
75 if (pollfds[i].revents) {
76 rc = waiters[i].callback(waiters[i].arg);
79 waiter_remove(&waiters[i]);