aboutsummaryrefslogtreecommitdiff
path: root/Utility/libkqueue.c
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@fischer.debian.org>2012-06-18 20:33:27 +0000
committerGravatar Joey Hess <joey@kitenet.net>2012-06-18 16:34:08 -0400
commitd680ff7ef06a3b0c8310836b03446e89d0ff9764 (patch)
treee0f907503d704057ab0edf3a846cef9d7eaade36 /Utility/libkqueue.c
parent90d565149abd7d752e22beb4aa57bf99522e5851 (diff)
kqueue code compiles on debian kfreebsd
Diffstat (limited to 'Utility/libkqueue.c')
-rw-r--r--Utility/libkqueue.c55
1 files changed, 27 insertions, 28 deletions
diff --git a/Utility/libkqueue.c b/Utility/libkqueue.c
index a919a60c7..999508f7e 100644
--- a/Utility/libkqueue.c
+++ b/Utility/libkqueue.c
@@ -13,10 +13,35 @@
#include <sys/event.h>
#include <sys/time.h>
+/* The specified fds are added to the set of fds being watched for changes.
+ * 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) {
+ int i, nev;
+ struct kevent evlist[1];
+ struct kevent chlist[fdcnt];
+
+ for (i = 0; i < fdcnt; i++) {
+ EV_SET(&chlist[i], fdlist[i], EVFILT_VNODE,
+ EV_ADD | EV_ENABLE | EV_CLEAR,
+ NOTE_WRITE,
+ 0, 0);
+ }
+
+ nev = kevent(kq, chlist, fdcnt, evlist, 1, timeout);
+
+ if (nev == 1)
+ return evlist[0].ident;
+ else
+ return -1;
+}
+
/* Initializes a kqueue, with a list of fds to watch for changes.
* Returns the kqueue's handle. */
int init_kqueue(const int fdcnt, const int *fdlist) {
- struct nodelay = {0, 0};
+ struct timespec nodelay = {0, 0};
int kq;
if ((kq = kqueue()) == -1) {
@@ -36,31 +61,5 @@ int init_kqueue(const int fdcnt, const int *fdlist) {
* Returns the fd that changed, or -1 on error.
*/
signed int waitchange_kqueue(const int kq) {
- helper(kq, 0, NULL, NULL);
-}
-
-/* The specified fds are added to the set of fds being watched for changes.
- * 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, cont struct *timeout) {
- int i, nev;
- struct kevent evlist[1];
- struct kevent chlist[fdcnt];
-
- for (i = 0; i < fdcnt; i++) {
- EV_SET(&chlist[i], fdlist[i], EVFILT_VNODE,
- EV_ADD | EV_ENABLE | EV_CLEAR,
- NOTE_WRITE,
- 1,
- timeout);
- }
-
- nev = kevent(info->kq, info->chlist, info->cnt, info->evlist,
- 1, NULL);
-
- if (nev == 1)
- return evlist[0].ident;
- else
- return -1;
+ return helper(kq, 0, NULL, NULL);
}