HP-UX Reference (11i v1 05/09) - 5 Miscellaneous Topics (vol 9)

a
aio(5) aio(5)
Manifest Constants
Certain values as defined by the POSIX standard are declared in
aio.h.
The following values are returned by the
aio_cancel()
function:
AIO_CANCELED All specified asynchronous I/O operations were successfully canceled.
AIO_NOTCANCELED
At least one specified asynchronous I/O operations was not successfully canceled.
AIO_ALLDONE All specified asynchronous I/O operations were completed before the request was
processed.
The following values are valid values of the
flags field that controls return from the lio_listio()
function:
LIO_WAIT Wait for all specified operations to complete.
LIO_NOWAIT Return without waiting for operations to complete.
The following values are operation codes supplied in the
aio_lio_opcode field the designate the type of
an operation started with
lio_listio() .
LIO_READ The aiocb specifies an asynchronous read operation.
LIO_WRITE The aiocb specifies an asynchronous write operation.
LIO_NOP The aiocb specifies no operation and is silently ignored.
Enqueuing of Operations
If an error condition is detected that prevents an operation from being started, aio_read() and
aio_write() do not enqueue a request. Instead they immediately return -1 and set errno to indicate
the cause of the failure. Once an operation has been successfully enqueued, calls to
aio_error() and
aio_return() must be used to determine the status of the operation and any error conditions, including
those normally reported by read() and write(). The request remains enqueued and consumes process
and system resources until aio_return() is called.
Error reporting of operations enqueued by lio_listio() may be less immediate than that of operations
enqueued by aio_read() and aio_write() . With the exception of resource shortages, errors for
which aio_read() and aio_write() would immediately return -1 and an errno value do not cause
lio_listio() to stop enqueuing the current or subsequent requests in its list. Instead, partial success
occurs. In this case, the application must use aio_error() to determine which operations in its list
have been enqueued and which resulted in errors.
Asynchronous I/O operations are said to be complete when one of the following is true:
The I/O transfer is performed successfully.
An error is detected in one or more parameters of the operation.
The operation is canceled.
If a valid sigevent is specified in the aiocb used to start the operation, then that signal is delivered
when the operation completes.
Reading and Writing Asynchronously
Asynchronous read and write operations are started using the aio_read(), aio_write() , and
lio_listio() interfaces. The parameters for each operation are provided in the aiocb used to start
the operation. A list of aiocb pointers can be provided to the lio_listio() function call, in which
case the type (read or write) of the operation is determined from the aio_lio_opcode field of the
aiocb. Once started, the I/O operations may proceed concurrently with execution of the process or thread
that initiated the operation.
With the implementation of HP-UX kernel threads, an application may achieve asynchronous I/O behavior
by using synchronous read() and write() functions from independent threads within the process.
However, the application may have to implement many of the status management facilities provided in the
POSIX Asynchronous I/O facility.
Waiting for Completion
The POSIX Asynchronous I/O facility supports both polling and notification models. The polling model is
implemented by repeatedly calling the aio_error() function to test the status of an operation. The
HP-UX 11i Version 1: September 2005 2 Hewlett-Packard Company Section 517