I've taken an initial shot at modifying Stdio.Fd and the Backend to support filesystem events using kqueue. It's not complete, but it doesn't seem to break anything at this point. I'm mostly interested in (implementation and design) feedback:
http://bill.welliver.org/dist/kqueue_events_7.8.601.diff
Some details off the top of my head:
1. adds constants for the VNODE events defined by kqueue() when it's present. These are present in files, and thus show up in Stdio. There's a constant __HAVE_FS_EVENTS__ that indicates whether the flags should be present. Would it make sense for these flags to be generic rather than kqueue specific?
2. adds set_fs_event_callback(cb, event_mask) to Stdio.Fd. The callback receives the event mask that triggered the event.
3. fs event callbacks are only triggered when the backend is running.
4. currently, the pike level glue to make it behave like the other callbacks is not present, and i'm not sure the extent to which that should be included. For example, it is probably not feasible to add support to set_callbacks(), as the event mask would also need to be set somehow, etc.
5. there's no way to un-register a given fs event currently, though set_blocking() and set_nonblocking() both seem to disable the events.
6. the callbacks are always present but obviously don't result in any events if you're not using a kqueue backend.
7. there's currently no way to retrieve the event mask. Not sure the best way to do this, as the event mask is really only stored in the fd_callback_box or the kernel (where it's really inaccessible).
8. i'd eventually like to add support for process, signal and timer events, but they'd probably have to be added as methods to the backend directly, as they don't involve an fd.
Example:
int main() { s = Stdio.File("/tmp/t1"); s->set_fs_event_callback(lambda(mixed ...args){werror("%O\n", args);}, Stdio.NOTE_WRITE|Stdio.NOTE_RENAME); return -1; }
As always, comments and suggestions are most appreciated!
Bill