diff options
author | Joey Hess <joey@kitenet.net> | 2012-06-18 21:46:04 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-06-18 21:46:04 -0400 |
commit | 5e9fdac92fe91a60d8f4570ec5d785976fe6c3ee (patch) | |
tree | 95251cb6c45441eb6b8616aeb93ee2adfefb46b4 /Utility/libkqueue.c | |
parent | 2bfcc0b09c5dd37c5e0ab65cb089232bfcc31934 (diff) |
update kqueue when new directories are added
Diffstat (limited to 'Utility/libkqueue.c')
-rw-r--r-- | Utility/libkqueue.c | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/Utility/libkqueue.c b/Utility/libkqueue.c index 5b38cdd33..b7f9595dc 100644 --- a/Utility/libkqueue.c +++ b/Utility/libkqueue.c @@ -18,11 +18,12 @@ * Fds passed to prior calls still take effect, so it's most efficient to * not pass the same fds repeatedly. */ -signed int helper(const int kq, const int fdcnt, const int *fdlist, - struct timespec *timeout) { +signed int helper(const int kq, const int fdcnt, const int *fdlist, int nodelay) { int i, nev; struct kevent evlist[1]; struct kevent chlist[fdcnt]; + struct timespec avoiddelay = {0, 0}; + struct timespec *timeout = nodelay ? &avoiddelay : NULL; for (i = 0; i < fdcnt; i++) { EV_SET(&chlist[i], fdlist[i], EVFILT_VNODE, @@ -43,30 +44,27 @@ signed int helper(const int kq, const int fdcnt, const int *fdlist, return -1; } -/* Initializes a kqueue, with a list of fds to watch for changes. - * Returns the kqueue's handle. */ +/* Initializes a new, empty kqueue. */ int init_kqueue(const int fdcnt, const int *fdlist) { - struct timespec nodelay = {0, 0}; int kq; - if ((kq = kqueue()) == -1) { perror("kqueue"); exit(1); } - - /* Prime the pump with the list of fds, but don't wait for any - * change events. */ - helper(kq, fdcnt, fdlist, &nodelay); - return kq; } +/* Adds fds to the set that should be watched. */ +void addfds_kqueue(const int kq, const int fdcnt, const int *fdlist) { + helper(kq, fdcnt, fdlist, 1); +} + /* Waits for a change event on a kqueue. * * Returns the fd that changed, or -1 on error. */ signed int waitchange_kqueue(const int kq) { - return helper(kq, 0, NULL, NULL); + return helper(kq, 0, NULL, 0); } /* @@ -74,7 +72,8 @@ main () { int list[1]; int kq; list[0]=open(".", O_RDONLY); - kq = init_kqueue(1, list); + kq = init_kqueue(); + addfds_kqueue(kq, 1, list) printf("change: %i\n", waitchange_kqueue(kq)); } */ |