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);
32 waiter = &waiters[n_waiters - 1];
35 waiter->events = events;
36 waiter->callback = callback;
42 void waiter_remove(struct waiter *waiter)
47 assert(i >= 0 && i < n_waiters);
50 memmove(&waiters[i], &waiters[i+1],
51 (n_waiters - i) * sizeof(waiters[0]));
53 waiters = talloc_realloc(NULL, waiters, struct waiter, n_waiters);
58 static struct pollfd *pollfds;
62 if (n_waiters != n_pollfds) {
63 pollfds = talloc_realloc(NULL, pollfds,
64 struct pollfd, n_waiters);
65 n_pollfds = n_waiters;
68 for (i = 0; i < n_waiters; i++) {
69 pollfds[i].fd = waiters[i].fd;
70 pollfds[i].events = waiters[i].events;
71 pollfds[i].revents = 0;
74 rc = poll(pollfds, n_waiters, -1);
79 for (i = 0; i < n_waiters; i++) {
80 if (pollfds[i].revents) {
81 rc = waiters[i].callback(waiters[i].arg);
84 waiter_remove(&waiters[i]);