kqueue for sockets on freebsd (non-polling)

Marc Lehmann schmorp at schmorp.de
Wed Jan 9 16:58:35 CET 2008

On Wed, Jan 09, 2008 at 01:20:35AM -0800, Eric Brown <yogieric.list at gmail.com> wrote:
> Anyway, I read a number of concerns about libev & kqueue.

What concerns? libev supports kqueue just fine... It is kqueue that is making
problems on most BSDs, though.

> Since all I care about are sockets, can I get libev to use kqueue in an
> efficient non-polling mode? Or am I better off looking at libevent or
> using kqueue directly?

What do you mean with "kqueue in non-polling mode"? afaik, kqueue only
supports a polling mode, and this is what both libevent and libev use.

> Sorry, I'm new to libev and kqueue - more used to using select()  
> directly or other higher level APIs. But libev looks really great.

Thanks. While, of course, I think that libev has a lot of advantages over
libevent (such as a more rational API (espeically when multithreading) and
higher performance), libevent is certainly adequate to the job as well.

You should probably look at the libevent example program, and the libev
documentation (which also has examples) and choose the one that appeals most
to you.

If you are only interested in sockets and simple timeouts, then both
libraries have the same feature set (although understanding how timeouts
work in libevent can be difficult, it certainly was for me).

libevent example: http://monkey.org/~provos/libevent/event-test.c
libevent docs: http://monkey.org/~provos/libevent/doxygen/
libev docs: http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod

If you insist on using kqueue everywhere (watch out, its buggy on most os
x releases even for sockets), then this will give you an event loop using
kqueue in libev, whenever kqueue is available:

   #include <ev.h>

   struct ev_loop *loop =
      ev_loop_new (
         ev_recommended_backends () | EVBACKEND_KQUEUE

   assert ((loop, "libev initialisation failed"));

                The choice of a       Deliantra, the free code+content MORPG
      -----==-     _GNU_              http://www.deliantra.net
      ----==-- _       generation
      ---==---(_)__  __ ____  __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      pcg at goof.com
      -=====/_/_//_/\_,_/ /_/\_\

More information about the libev mailing list