linux-inotify 0.2.0.0 → 0.2.0.1
raw patch · 2 files changed
+17/−27 lines, 2 files
Files
- linux-inotify.cabal +3/−3
- src/System/Linux/Inotify.hsc +14/−24
linux-inotify.cabal view
@@ -1,5 +1,5 @@ name: linux-inotify-version: 0.2.0.0+version: 0.2.0.1 synopsis: Thinner binding to the Linux Kernel's inotify interface description: This is a binding for GHC 7 to the Linux Kernel's inotify interface,@@ -28,7 +28,7 @@ 1. Due to the use of `inotify_init1`, `linux-inotify` currently requires linux 2.6.27 or later, even though `inotify` support debuted in linux 2.6.13. You can check which version of linux is- on a machine via `uname -a`. I would like to fix this at some point,+ on a machine via `uname` `-a`. I would like to fix this at some point, but it isn't a personal priority. . 2. `linux-inotify` requires GHC 7.0.2 or later, whereas `hinotify`@@ -59,4 +59,4 @@ source-repository this type: git location: http://github.com/lpsmith/linux-inotify- tag: v0.2.0.0+ tag: v0.2.0.1
src/System/Linux/Inotify.hsc view
@@ -250,7 +250,7 @@ -- | A union of all flags above; this is not a separate flag but a convenience -- definition. in_ALL_EVENTS :: Mask a-in_ALL_EVENTS = Mask (#const IN_OPEN)+in_ALL_EVENTS = Mask (#const IN_ALL_EVENTS) -- | (since Linux 2.6.15) Don't dereference pathname if it is a symbolic link. in_DONT_FOLLOW :: Mask WatchFlag@@ -374,7 +374,8 @@ where flags = (#const IN_NONBLOCK) .|. (#const IN_CLOEXEC) -- | Adds a watch on the inotify descriptor, returns a watch descriptor.--- This function is thread safe.+-- The mask controls which events are delivered to your application,+-- as well as some additional options. This function is thread safe. addWatch :: Inotify -> FilePath -> Mask WatchFlag -> IO Watch addWatch Inotify{fd} path !mask =@@ -463,9 +464,7 @@ getEvent :: Inotify -> IO Event getEvent inotify@Inotify{..} = do fillBufferBlocking inotify "System.Linux.Inotify.getEvent"- evt <- peekMessage inotify- consumeMessage inotify- return evt+ getMessage True inotify -- | Returns an inotify event, blocking until one is available. --@@ -479,7 +478,7 @@ peekEvent :: Inotify -> IO Event peekEvent inotify@Inotify{..} = do fillBufferBlocking inotify "System.Linux.Inotify.peekEvent"- peekMessage inotify+ getMessage False inotify hasEmptyBuffer :: Inotify -> IO Bool hasEmptyBuffer Inotify{..} = do@@ -527,8 +526,8 @@ then loop else throwErrno funcName -peekMessage :: Inotify -> IO Event-peekMessage Inotify{..} = withForeignPtr buffer $ \ptr0 -> do+getMessage :: Bool -> Inotify -> IO Event+getMessage doConsume Inotify{..} = withForeignPtr buffer $ \ptr0 -> do start <- readIORef startRef let ptr = ptr0 `plusPtr` start wd <- Watch <$> ((#peek struct inotify_event, wd ) ptr :: IO CInt)@@ -538,17 +537,10 @@ name <- if len == 0 then return B.empty else B.packCString ((#ptr struct inotify_event, name) ptr)+ when doConsume $ writeIORef startRef $! + start + (#size struct inotify_event) + fromIntegral len return $! Event{..}-{-# INLINE peekMessage #-}--consumeMessage :: Inotify -> IO ()-consumeMessage Inotify{..} = do- start <- readIORef startRef- len <- withForeignPtr buffer $ \ptr0 -> do- let ptr = ptr0 `plusPtr` start- (#peek struct inotify_event, len ) ptr :: IO Word32- writeIORef startRef $! start + (#size struct inotify_event) + fromIntegral len-{-# INLINE consumeMessage #-}+{-# INLINE getMessage #-} -- | Returns an inotify event only if one is immediately available. --@@ -561,8 +553,7 @@ if isEmpty then return Nothing else do- evt <- peekMessage inotify- consumeMessage inotify+ evt <- getMessage True inotify return $! Just evt where funcName = "System.Linux.Inotify.getEventNonBlocking"@@ -582,7 +573,7 @@ if isEmpty then return Nothing else do- evt <- peekMessage inotify+ evt <- getMessage False inotify return $! Just evt where funcName = "System.Linux.Inotify.peekEventNonBlocking"@@ -596,8 +587,7 @@ if isEmpty then return Nothing else do- evt <- peekMessage inotify- consumeMessage inotify+ evt <- getMessage True inotify return $! Just evt -- | Returns an inotify event only if one is available in 'Inotify's@@ -613,7 +603,7 @@ if isEmpty then return Nothing else do- evt <- peekMessage inotify+ evt <- getMessage False inotify return $! Just evt -- | Closes an inotify descriptor, freeing the resources associated