diff options
author | Camil Staps | 2020-01-06 16:27:27 +0100 |
---|---|---|
committer | Camil Staps | 2020-01-06 16:27:27 +0100 |
commit | ba1b279a40c6b491ccd352bf22b888ae7dfbad97 (patch) | |
tree | af08dec7afefa240e94a3c0f7bd01d3aaa24acec /Inotify.icl | |
parent | Cleanup example (diff) |
Expose Inotify type itself in callbacks to allow adding/removing watches
Diffstat (limited to 'Inotify.icl')
-rw-r--r-- | Inotify.icl | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/Inotify.icl b/Inotify.icl index acf56b9..fcd1d60 100644 --- a/Inotify.icl +++ b/Inotify.icl @@ -17,12 +17,6 @@ import System._Posix import code from "inotify_c.o" -:: *Inotify st = - { fd :: !Int - , watches :: ![(INWatch, INCallback st)] - , state :: !st - } - :: INWatch :== Int (|-) infixl 6 :: (INMask INMask -> INMask) @@ -87,21 +81,20 @@ where 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 } + inot & fd = fd | not ok = (inot, w) | (size wds) rem 4 <> 0 || (size masks) rem 4 <> 0 = (inot,w) # (wds,masks,fnames) = (split 4 wds, split 4 masks, splitOn '\0' fnames) | length wds <> length masks = (inot, w) # infos = zip3 (map bytesToInt wds) (map bytesToInt masks) fnames - # (fd,st,w`) = seq (map (check infos) watches) (inot.fd, state, w) - = ({ inot & fd=fd, state=st }, w`) + = seq (map (check infos) watches) (inot, w) where - check :: [(Int,Int,String)] (INWatch, INCallback st) *(Int, st, *World) - -> *(Int, st, *World) - check infos (watch,f) (fd,st,w) + check :: [(Int,Int,String)] (INWatch, INCallback st) *(*Inotify st, *World) + -> *(*Inotify st, *World) + check infos (watch,f) (st,w) # (st,w) = seq [\(st,w) -> f mask (toMaybe name) st w \\ (wd,mask,name) <- infos | wd == watch] (st,w) - = (fd,st,w) + = (st,w) where toMaybe :: String -> Maybe String toMaybe s = if (s=="") Nothing (Just s) |