PATCH: Integrating libev with other runloops

Rasmus Andersson rasmus at
Sat Oct 23 18:36:13 CEST 2010

Greetings, knights of libev.

I'm part of the node.js dev community and are working on a library
version of node (which can be embedded in other programs). Many "host"
systems already use a runloop system of their own (e.g. OS X
applications use something called CFRunLoop) thus there's a need to
have node running in symbios with these systems.

For this to work smoothly there's some information related to a libev
runloop which is not exposed through the API. We added the following
four functions:

• ev_backend_fd -- ability to acquire the FD used by the backend (e.g.
to register for events so the parent runloop can yield for libev when

• ev_refcount -- ability to know the number of active events, so the
runloop iteration invocation can be optimized.

• ev_loop_fdchangecount -- ability to know when to stop yielding for libev

• ev_loop_next_waittime -- ability to know when to next invoke ev_loop.

In our current implementation, we call the following function when
needed (either because backend FD has pending changes or waittime

void NodeLoopIteration() {
 while(ev_loop_fdchangecount() != 0) {

I've attached the patch we created. It's very rudimentary and the only
real code (ev_loop_next_waittime) is copy-pasted from ev_loop.

Would really appreciate this patch being integrated!

Thank you.

Rasmus Andersson
-------------- next part --------------
A non-text attachment was scrubbed...
Name: libev.patch
Type: application/octet-stream
Size: 3427 bytes
Desc: not available
URL: <>

More information about the libev mailing list