NAME
aio - Asynchronous IO
SYNOPSIS
#include <errno.h>
#include <aio.h>
DESCRIPTION
The POSIX.1b standard defines a new set of I/O operations which can
significantly reduce the time an application spends waiting at I/O. The
new functions allow a program to initiate one or more I/O operations and
then immediately resume normal work while the I/O operations are
executed in parallel. This functionality is available if the
R unistd.h
file defines the symbol
_POSIX_ASYNCHRONOUS_IO
.
These functions are part of the library with realtime functions named
R librt
R libc
binary.
The implementation of these functions can be done using support in the
kernel (if available) or using an implementation based on threads at
userlevel. In the latter case it might be necessary to link applications
with the thread library
R libpthread
in addition to
R librt
and
R libaio
.
All AIO operations operate on files which were opened previously. There
might be arbitrarily many operations running for one file. The
asynchronous I/O operations are controlled using a data structure named
R struct aiocb
It is defined in
R aio.h
as follows.
struct aiocb
{
int aio_fildes; /* File desriptor. */
int aio_lio_opcode; /* Operation to be performed. */
int aio_reqprio; /* Request priority offset. */
volatile void *aio_buf; /* Location of buffer. */
size_t aio_nbytes; /* Length of transfer. */
struct sigevent aio_sigevent; /* Signal number and value. */
/* Internal members. */
struct aiocb *__next_prio;
int __abs_prio;
int __policy;
int __error_code;
__ssize_t __return_value;
#ifndef __USE_FILE_OFFSET64
__off_t aio_offset; /* File offset. */
char __pad[sizeof (__off64_t) - sizeof (__off_t)];
#else
__off64_t aio_offset; /* File offset. */
#endif
char __unused[32];
};
The POSIX.1b standard mandates that the
R struct aiocb
structure
contains at least the members described in the following table. There
might be more elements which are used by the implementation, but
depending upon these elements is not portable and is highly deprecated.
R int aio_fildes
This element specifies the file descriptor to be used for the
operation. It must be a legal descriptor, otherwise the operation will
fail.
The device on which the file is opened must allow the seek operation.
I.e., it is not possible to use any of the AIO operations on devices
like terminals where an
R lseek
call would lead to an error.
R off_t aio_offset
This element specifies the offset in the file at which the operation (input
or output) is performed. Since the operations are carried out in arbitrary
order and more than one operation for one file descriptor can be
started, one cannot expect a current read/write position of the file
descriptor.
R volatile void *aio_buf
This is a pointer to the buffer with the data to be written or the place
where the read data is stored.
R size_t aio_nbytes
This element specifies the length of the buffer pointed to by
R aio_buf
.
R int aio_reqprio
If the platform has defined
_POSIX_PRIORITIZED_IO
and
_POSIX_PRIORITY_SCHEDULING
, the AIO requests are
processed based on the current scheduling priority. The
R aio_reqprio
element can then be used to lower the priority of the
AIO operation.
R struct sigevent aio_sigevent
This element specifies how the calling process is notified once the
operation terminates. If the
R sigev_notify
element is
SIGEV_NONE
, no notification is sent. If it is
SIGEV_SIGNAL
,
the signal determined by
R sigev_signo
is sent. Otherwise,
R sigev_notify
must be
SIGEV_THREAD
is created which starts executing the function pointed to by
R sigev_notify_function
.
R int aio_lio_opcode
This element is only used by the
R lio_listio
and
R lio_listio64
functions. Since these functions allow an
arbitrary number of operations to start at once, and each operation can be
input or output (or nothing), the information must be stored in the
control block. The possible values are:
LIO_READ
Start a read operation. Read from the file at position
R aio_offset
and store the next
R aio_nbytes
bytes in the
buffer pointed to by
R aio_buf
.
LIO_WRITE
Start a write operation. Write
R aio_nbytes
bytes starting at
R aio_buf
into the file starting at position
R aio_offset
.
LIO_NOP
Do nothing for this control block. This value is useful sometimes when
an array of
R struct aiocb
values contains holes, i.e., some of the
values must not be handled although the whole array is presented to the
R lio_listio
function.
When the sources are compiled using
_FILE_OFFSET_BITS == 64
on a
32 bit machine, this type is in fact
R struct aiocb64
, since the LFS
interface transparently replaces the
R struct aiocb
definition.
For use with the AIO functions defined in the LFS, there is a similar type
defined which replaces the types of the appropriate members with larger
types but otherwise is equivalent to
R struct aiocb
all member names are the same.
/* The same for the 64bit offsets. Please note that the members aio_fildes
to __return_value have to be the same in aiocb and aiocb64. */
#ifdef __USE_LARGEFILE64
struct aiocb64
{
int aio_fildes; /* File desriptor. */
int aio_lio_opcode; /* Operation to be performed. */
int aio_reqprio; /* Request priority offset. */
volatile void *aio_buf; /* Location of buffer. */
size_t aio_nbytes; /* Length of transfer. */
struct sigevent aio_sigevent; /* Signal number and value. */
/* Internal members. */
struct aiocb *__next_prio;
int __abs_prio;
int __policy;
int __error_code;
__ssize_t __return_value;
__off64_t aio_offset; /* File offset. */
char __unused[32];
};
R int aio_fildes
This element specifies the file descriptor which is used for the
operation. It must be a legal descriptor since otherwise the operation
fails for obvious reasons.
The device on which the file is opened must allow the seek operation.
I.e., it is not possible to use any of the AIO operations on devices
like terminals where an
R lseek
call would lead to an error.
R off64_t aio_offset
This element specifies at which offset in the file the operation (input
or output) is performed. Since the operation are carried in arbitrary
order and more than one operation for one file descriptor can be
started, one cannot expect a current read/write position of the file
descriptor.
R volatile void *aio_buf
This is a pointer to the buffer with the data to be written or the place
where the read data is stored.
R size_t aio_nbytes
This element specifies the length of the buffer pointed to by
R aio_buf
.
R int aio_reqprio
If for the platform
_POSIX_PRIORITIZED_IO
and
_POSIX_PRIORITY_SCHEDULING
are defined the AIO requests are
processed based on the current scheduling priority. The
R aio_reqprio
element can then be used to lower the priority of the
AIO operation.
R struct sigevent aio_sigevent
This element specifies how the calling process is notified once the
operation terminates. If the
R sigev_notify
, element is
SIGEV_NONE
no notification is sent. If it is
SIGEV_SIGNAL
,
the signal determined by
R sigev_signo
is sent. Otherwise,
R sigev_notify
must be
SIGEV_THREAD
in which case a thread
which starts executing the function pointed to by
R sigev_notify_function
.
R int aio_lio_opcode
This element is only used by the
R lio_listio
and
R lio_listio64
functions. Since these functions allow an
arbitrary number of operations to start at once, and since each operation can be
input or output (or nothing), the information must be stored in the
control block. See the description of
R struct aiocb
for a description
of the possible values.
When the sources are compiled using
_FILE_OFFSET_BITS == 64
on a
32 bit machine, this type is available under the name
R struct aiocb64
, since the LFS transparently replaces the old interface.
RETURN VALUES
ERRORS
SEE ALSO
R aio_cancel(3),
R aio_cancel64(3),
R aio_error(3),
R aio_error64(3),
R aio_fsync(3),
R aio_fsync64(3),
R aio_init(3),
R aio_read(3),
R aio_read64(3),
R aio_return(3),
R aio_return64(3),
R aio_suspend(3),
R aio_suspend64(3),
R aio_write(3),
R aio_write64(3),
R errno(3),