summaryrefslogtreecommitdiff
path: root/Utility/Kqueue.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-06-18 12:25:20 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-06-18 12:25:20 -0400
commit3c8a9043b6fc8fafbeac16e8f9199a0d12870549 (patch)
treed3efa261e61f19b3aea254409cb2c144886f5d05 /Utility/Kqueue.hs
parent0ecc7dc8927b3840d6a7ba4d39c344f3e962580e (diff)
skeleton C library for calling kqueue
Diffstat (limited to 'Utility/Kqueue.hs')
-rw-r--r--Utility/Kqueue.hs31
1 files changed, 31 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