diff options
Diffstat (limited to 'Inotify.icl')
-rw-r--r-- | Inotify.icl | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/Inotify.icl b/Inotify.icl index e676f03..205aba9 100644 --- a/Inotify.icl +++ b/Inotify.icl @@ -42,8 +42,8 @@ where ccall close "I:V:A" } -inotify_add_watch :: (INCallback st) !Int !String !*(Inotify st) - -> *(Either Int INWatch, *Inotify st) +inotify_add_watch :: (INCallback st) !INMask !String !*(Inotify st) + -> *(!Either Int INWatch, !*Inotify st) inotify_add_watch f mask fname inot=:{fd,watches} = let (w, fd`) = c_add_watch fd fname mask in ( if (w == -1) (Left errno) (Right w) @@ -55,7 +55,7 @@ where ccall clean_inotify_add_watch "ISI:VII" } -inotify_rm_watch :: !INWatch !*(Inotify st) -> *(Bool, *Inotify st) +inotify_rm_watch :: !INWatch !*(Inotify st) -> *(!Bool, !*Inotify st) inotify_rm_watch w inot=:{fd} = case c_inotify_rm_watch fd w of (0, fd`) = (True, {inot & fd=fd`}) (_, fd`) = (False, {inot & fd=fd`}) @@ -65,15 +65,17 @@ where ccall clean_inotify_rm_watch "II:VII" } -inotify_poll :: *(Inotify st) -> *Inotify st -inotify_poll inot=:{fd} = let (_,fd`) = c_poll fd in { inot & fd=fd` } +inotify_poll :: !(Maybe Int) !*(Inotify st) -> *(!Int, !*Inotify st) +inotify_poll mbTo inot=:{fd} = let (n,fd`)=c_poll fd to in (n, {inot & fd=fd`}) where - c_poll :: !*Int -> *(!Int, !*Int) - c_poll fd = code { - ccall clean_poll "I:VII" + to = if (isNothing mbTo) -1 (fromJust mbTo) + + c_poll :: !*Int !Int -> *(!Int, !*Int) + c_poll fd timeout = code { + ccall clean_poll "II:VII" } -inotify_check :: *(Inotify st) *World -> *(*Inotify st, *World) +inotify_check :: !*(Inotify st) !*World -> *(!*Inotify st, !*World) inotify_check inot=:{fd,watches,state} w # (ok, wds, masks, fnames, fd) = c_check fd inot = { inot & fd=fd } @@ -117,11 +119,18 @@ where ccall clean_inotify_check "I:VISSSI" } -inotify_loop_forever :: *(Inotify st) *World -> *(*Inotify st, *World) -inotify_loop_forever inot w - # inot = inotify_poll inot +inotify_is_event :: INMask INEvent -> Bool +inotify_is_event mask ev = ev bitand mask <> 0 + +inotify_loop_with_timeout :: !(Maybe Int) !*(Inotify st) !*World -> *(!*Inotify st, !*World) +inotify_loop_with_timeout to inot w + # (n,inot) = inotify_poll to inot + | n == 0 = (inot,w) # (inot,w) = inotify_check inot w - = inotify_loop_forever inot w + = inotify_loop_with_timeout to inot w + +inotify_loop_forever :: !*(Inotify st) !*World -> *(!*Inotify st, !*World) +inotify_loop_forever inot w = inotify_loop_with_timeout Nothing inot w errno :: Int errno = err 0 |