Am I right in thinking that AIO completion notifications (whether done via threads or signals) give you no information as to which request has completed? Is there any way to accomplish this correlation other than having separate callback functions called for each request? Ostensibly you can use the original request's aiocb structure to make calls to aio_error and aio_return, but you don't get a pointer back to the aiocb structure as part of the notification callback. Why does there seem to be no mechanism to do this?
When you submit a struct aiocb
to initiate the asynchronous IO, you're allowed to populate its aio_sigevent
member with a struct sigevent
structure:
struct sigevent {
int sigev_notify; /* Notification method */
int sigev_signo; /* Notification signal */
union sigval sigev_value; /* Data passed with
notification */
/* ... */
}
union sigval { /* Data passed with notification */
int sival_int; /* Integer value */
void *sival_ptr; /* Pointer value */
};
Using aio_sigevent.sigev_value.sival_ptr
you can store a pointer to your struct aiocb
(or another structure that has your struct aiocb
as a member) which you can then look up when your signal handler is called:
si->si_value.sival_ptr;
The aio(7)
manpage was extremely helpful when researching this and the sigevent(7)
manpage has details on the struct sigevent
structure.