Advanced Programming in the UNIX® Environment

(lily) #1
ptg10805159

Section 14.5 Asynchronous I/O 515


If an asynchronous I/O operation is successfully canceled, calling theaio_error
function on the corresponding AIO control block will return the errorECANCELED.If
the operation can’t be canceled, then the corresponding AIO control block is unchanged
by the call toaio_cancel.
One additional function is included with the asynchronous I/O interfaces, although
it can be used in either a synchronous or an asynchronous manner.Thelio_listio
function submits a set of I/O requests described by a list of AIO control blocks.
#include <aio.h>
int lio_listio(intmode,struct aiocb *restrict const list[restrict],
intnent,struct sigevent *restrictsigev);
Returns: 0 if OK,−1 on error

Themodeargument determines whether the I/O is truly asynchronous. When it is set to
LIO_WAIT,thelio_listiofunction won’t return until all of the I/O operations
specified by the list arecomplete. In this case, thesigevargument is ignored. When the
modeargument is set toLIO_NOWAIT,then thelio_listiofunction returns as soon as
the I/O requests arequeued. The process is notified asynchronously when all of the
I/O operations complete, as specified by thesigevargument. If we don’t want to be
notified, we can set sigevto NULL.Note that the individual AIO control blocks
themselves may also enable asynchronous notification when an individual operation
completes. The asynchronous notification specified by thesigevargument is in addition
to these, and is sent only when all of the I/O operations complete.
The list argument points to a list of AIO control blocks specifying the I/O
operations to perform. Thenentargument specifies the number of elements in the array.
The list of AIO control blocks can containNULLpointers; these entries areignored.
In each AIO control block, theaio_lio_opcode field specifies whether the
operation is a read (LIO_READ), a write (LIO_WRITE), or a no-op (LIO_NOP), which is
ignored. Aread is treated as if the corresponding AIO control block had been passed to
theaio_readfunction. Similarly,awrite is treated as if the AIO control block had
been passed toaio_write.
Implementations can limit the number of asynchronous I/O operations we are
allowed to have outstanding. The limits areruntime invariants, and aresummarized in
Figure14.19.

Name Description Minimum acceptable value
AIO_LISTIO_MAX maximum number of I/O operations _POSIX_AIO_LISTIO_MAX( 2 )
in a single list I/O call
AIO_MAX maximum number of outstanding _POSIX_AIO_MAX( 1 )
asynchronous I/O operations
AIO_PRIO_DELTA_MAX maximum amount by which a process 0
can decrease its asynchronous
I/O priority level

Figure 14.19POSIX.1 runtime invariant values for asynchronous I/O
Free download pdf