watching for new files: libevent vs. libev

Marc Lehmann schmorp at
Thu Apr 4 23:09:36 CEST 2013

On Thu, Apr 04, 2013 at 04:04:55PM -0400, "Mikhail T." <mi+thun at> wrote:
> Having used both kqueue and inotify directly in the past, I'm only just
> starting searching for cross-platform libraries, that would hide
> OS-specific methods from the application.

libev does, but within the limitations of portability. for example, there
doesn't seem to be a way to implement ev_stat watchers with kqueue, and
inotify can only provide hints in some cases (inotify is use by libev for

however, the end result is really the same on all platforms, that is,
changes can be missed when they are happening fast, and this is still the
best that is apparently possible, even on systems with inotify and kqueue.

> So I don't have a ready answer. But the program I posted in the previous
> e-mail works as expected with EV_ET -- and does not work without it.

Which might mean it is buggy, or is written in a style that requires it. For
example, it might not compile with libve or glib, but neither of that menas
that EV_ET is required for directory change detection.

It's up to you to explain the connection between the two.

Looking at your program in more detail, it seems to be simply buggy, and
will probably not even work with libevent on freebsd, depending on which
backend is used.

> > See the documentation for details.
> Could you be more specific?

See ev_stat watchers.

> I need an event, whenever a new file is created in a directory. Can
> libev do that?

Not reliably - you can use an ev_stat watcher to see if the mtime changes,
and then scan for new file names, which might work well enough for your
use case.

Inotify can give you the name directly, but whether "new filename" means the
same thing as "new file" is another question :)

                The choice of a       Deliantra, the free code+content MORPG
      -----==-     _GNU_    
      ----==-- _       generation
      ---==---(_)__  __ ____  __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      schmorp at
      -=====/_/_//_/\_,_/ /_/\_\

More information about the libev mailing list