AIO integration

Paul Colomiets pc at
Sat May 3 12:48:48 CEST 2008

Again sorry for replying off-list initially, but I will use
this chance to add that event completion also
means that you don't need to couple every start()
call with stop() call. But some sort of that is exists
in ev_timer so it doesn't really something new for

Marc Lehmann wrote:
> On Thu, May 01, 2008 at 12:56:16PM -0400, Thomas Harning <harningt at> wrote:
>> I'd also be interested in such a development.  The real trick would be  
>> coming up with a nice uniform API for handling event completion rather  
>> than event readiness.
> Thats not an issue for aio, as completion == readyness (when you have read
> the data, it is both ready and the action has completed).
It's true, but it makes some sense if you consider that current
idiom using libev with sockets is:

buffer = malloc(SIZE);
bytes_to_go = fillbuffer(buffer);
current_pos = buffer;
ev::io watcher;

void on_ready(ev::io &,int) {
   if(bytes_to_go) {
       int written = write(sock, current_pos, bytes_to_go);
       current_pos += written;
       bytes_to_go -= written;
   if(bytes_to_go <= 0) {

Using AIO which also exists for sockets, it's something like:

buffer = malloc(SIZE);
bytes_to_go = fillbuffer(buffer);
ev::aio watcher;
watcher.start(sock, ev::WRITE, buffer); // no position for socket

void on_ready(ev::aio &,int) {
   // watcher.stop(); // may be, but probably not

(probably I'd rename watcher and on_ready but
it should be as close as possible as example)

It was not my original intent to propose that addition
(it can be implemented without aio by hiding non-bloking
reading/writing code into the libev's event loop). But it can
be taken in account while designing API for aio.

More information about the libev mailing list