while(aio_error(&cb) == EINPROGRESS)
close(file);
is actually
while(aio_error(&cb) == EINPROGRESS)
close(file);
Did you mean to busy wait until the write completed instead?
while(aio_error(&cb) == EINPROGRESS);
// ^
close(file);