How does libev know when socket is ready to be read?

Marc Lehmann schmorp at
Fri Nov 9 15:53:03 CET 2012

On Sat, Nov 10, 2012 at 12:26:12AM +1300, A G <utopian201 at> wrote:
> How does libev get notification that a socket (ev_io) is ready to be read, is it through a signal from the kernel?

See "man poll" for a typical example.

> However when I have the watcher attached to my tcp/ip stack in userspace, when it is ready to be read from, the callback doesn't get invoked. I'm guessing this is because libev gets a notification from the kernel, a notification that never comes from my tcp/ip stack.


> I would like to make it work with my userspace tcp stack, but don't know where to start learning. Which libev files should I start reading? There are quite a lot!

Why would you want to? Your userspace stack could just call the callback
in your program directly. Conversely, libev has no watcher types for your
userspace network stack.

The most sensible way for you is to provide comaotible read/write/poll (or
maybe kqueue) etc. functions, then libev will work automatically.

Or in other words, there already is a perfetcly fine API for networking,
the bsd sockets API. Implement it, and all programs magically start to

> Also how do I find out which mechanism libev is using? eg epoll, select etc

By reading the libev documentation and applying it's wisdom :)

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

More information about the libev mailing list