|
|
This section tells you how to use the four interface functions:
aio_read and aio_write allow an application to request an asynchronous read or asynchronous write operation. When initiating an asynchronous read or write, you can request asynchronous notification by supplying the address of a user-defined handler to be invoked when the I/O has completed. Since the address of the aiocb control block is passed as an argument to the handler, the I/O request that completed is easily identified and you need only implement one handler.
An application may request asynchronous notification by supplying the address of a user-defined handler to be called on completion of the Asynchronous I/O request. This enables the application to perform other work while the I/O is in progress and guarantees that the application will be notified at the time the I/O completes so that any processing on that data may be performed immediately, if so desired.
For threads-based Asynchronous I/O, an application may also use the aio_suspend interface to block until at least one I/O operation completes or a timeout period expires. This interface is flexible because it enables any thread within a process to ask about one or more outstanding Asynchronous I/O operations and can specify how long to wait.
The aio_suspend routine returns 0 if at least one matching I/O request completed.
A null pointer is returned on failure and errno is set to indicate that the timeout expired (ETIME) or an interrupt occurred (EINTR).
Although rarely needed, aio_cancel is the only way to cancel an Asynchronous I/O request that has been blocked for input from a remote host that just crashed. Requests that have not been started are canceled, but those in progress may or may not be canceled.