Request for Comments on linux-inotify: a new, thinner binding to filesystem events on linux
github.com/lpsmith/linux-inotifyPosted Mar 7, 2013, 3:37 AM UTC
Posted Mar 7, 2013, 3:37 AM UTC
Just nitpick: Several places in the readme have linux-notifiy instead of linux-inotify.
Otherwise, seems like a nice library.
I started looking at ways to improve hinotify. The main problem I saw was the use of multiple threads for an interface that only provides a callback that swallows exceptions.
My thought was that instead there should be a stream-like interface, and that the lowest-common denominator for that in Haskell is a Chan. Although this separates the library consumer from the producer, it is inefficient if there are a huge amount of events and not all of them are getting processed. A bounded Chan would be necessary to avoid memory leaking. But the program would try to bring all the events into Haskell land, whereas reading events on demand means inotify itself can just overflow when there are too many events and they don't all have to come into Haskell.
getEvent is good because it will pull on demand, so it seems like the building block for a streaming interface.
Let me know when this library matures so it can be rolled into: https://github.com/mdittmer/hfsnotify
Probably the most interesting things here would be the discussion of ignoring
inotify_rm_watch'sEINVAL, the idea about an alternative Haskell representation of watch descriptors, and possibly the implementation of getEvent.For
Watch, you may consider offering both options: the safer one that includes theFdinside of it for simpler deallocations and the unsafe one that takes up less memory for the purpose of storage within data structures. Then users can decide which version they prefer.Yeah, I've been thinking towards having a very minimal wrapper of inotify, not unlike what's already there, and maybe having a few additional wrappers with extra features, perhaps even some kind of event router not entirely unlike hinotify.
There are still
EventMaskvalues I need to add, as well as a convenient way of testing the incomingEventMaskfor what kind of event happened.I'm usually inclined to make just about any change that allows lines of caveats & explanation in documentation to be removed, but can't really judge the tradeoffs here.
Could you hide
Inotify,initandcloseif you build the API around a newtype-wrappedReaderT Inotify IO?Well, the problem with that is that most use cases would involve interfacing that newtyped-wrapped monad to other application monads. So you'd probably need to make it a monad transformer, something like
But to be honest, I've soured on the idea of an application monad in many but not all cases for a couple of reasons: the problem of combining disparate application monads, the fact that adding features via monad transformers doesn't pay it's own way, dealing with exception handling, etc.
So such a monad transformer might be worth considering adding to the base package as an optional wrapper. But I certainly couldn't require it, as it doesn't pay its own way.
Sure, in some cases the GHC optimizer might be able to optimize the extra overhead of
InotifyMin code that doesn't use Inotify ops, but these optimizations (like your observation regardingChan) don't really work across module boundaries, because the compiler has no way of knowing whether the foreign code is going to use the parameter or not.