summaryrefslogtreecommitdiff
path: root/Utility
diff options
context:
space:
mode:
Diffstat (limited to 'Utility')
-rw-r--r--Utility/Kqueue.hs31
-rw-r--r--Utility/libkqueue.c22
-rw-r--r--Utility/libkqueue.h1
3 files changed, 54 insertions, 0 deletions
diff --git a/Utility/Kqueue.hs b/Utility/Kqueue.hs
new file mode 100644
index 000000000..bfc6ee9fc
--- /dev/null
+++ b/Utility/Kqueue.hs
@@ -0,0 +1,31 @@
+{- BSD kqueue file modification notification interface
+ -
+ - Copyright 2012 Joey Hess <joey@kitenet.net>
+ -
+ - Licensed under the GNU GPL version 3 or higher.
+ -}
+
+{-# LANGUAGE ForeignFunctionInterface #-}
+
+module Utility.Kqueue ( waitChange ) where
+
+import Common
+
+import System.Posix.Types
+import Foreign.C.Types
+import Foreign.C.Error
+import Foreign.Ptr
+import Foreign.Marshal
+
+foreign import ccall unsafe "libkqueue.h waitchange" c_waitchange
+ :: Ptr Fd -> IO Fd
+
+waitChange :: [Fd] -> IO (Maybe Fd)
+waitChange fds = withArray fds $ \c_fds -> do
+ ret <- c_waitchange c_fds
+ ifM (safeErrno <$> getErrno)
+ ( return $ Just ret
+ , return Nothing
+ )
+ where
+ safeErrno (Errno v) = v == 0
diff --git a/Utility/libkqueue.c b/Utility/libkqueue.c
new file mode 100644
index 000000000..0ef42b801
--- /dev/null
+++ b/Utility/libkqueue.c
@@ -0,0 +1,22 @@
+/* kqueue interface, C mini-library
+ *
+ * Copyright 2012 Joey Hess <joey@kitenet.net>
+ *
+ * Licensed under the GNU GPL version 3 or higher.
+ */
+
+#include <errno.h>
+#include <stdio.h>
+
+/* Waits for a change event on one of the array of directory fds,
+ * and returns the one that changed. */
+int waitchange(const int *fds) {
+// if (kqueue(blah, &fds) != 0)
+// return 0; /* errno is set */
+// else
+ errno = 0;
+
+ printf("in waitchange!, %i %i\n", fds[0], fds[1]);
+
+ return fds[0];
+}
diff --git a/Utility/libkqueue.h b/Utility/libkqueue.h
new file mode 100644
index 000000000..75af9eeba
--- /dev/null
+++ b/Utility/libkqueue.h
@@ -0,0 +1 @@
+int waitchange(const int *fds);