skeleton C library for calling kqueue
This commit is contained in:
parent
0ecc7dc892
commit
3c8a9043b6
6 changed files with 75 additions and 11 deletions
31
Utility/Kqueue.hs
Normal file
31
Utility/Kqueue.hs
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue