using aio_read/write with libev - some ideas

Marc Lehmann schmorp at
Sat May 17 14:58:05 CEST 2008

Since many people believe they need only aio_read and aio_write (and not
something like eio), here are a few words on how I think one should integrate
aio_xxx into libev programs.

the sus aio functions let you specify a signal to be delivered (this is
usually quite slow) on completion, or a callback to be called

The ideal way to make use of that in libev programs is to create an ev_async
watcher and do your processing in its callback.

Then you should ste sigev_notify_function to a simple callback that
invokes ev_async_send on that watcher.

The only issue currently is that ev_async watcher processing is
O(#async-watchers), so it doesn't scale to a large number of watchers.

(I haven't found a way to reduce this effectively).

So a better approach would use a single ev_async watcher and a
mutex-locked queue where you queue which requests have been notified, and
unqueue them in the ev_async callback (libev unfortunately can't do that -
a signal/thread safe queue without locking would work wonders for me :)

I think it could be a nice exepriment to try to write a small library
that only offered this and would use overlapped I/O on completion ports
on windows as well, so one could have simple ev_aio_read and ev_aio_write
(maybe fsync) functions.

(An experiment I won't try to execute)

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

More information about the libev mailing list