NAME

io - Asynchronous IO

SYNOPSYS

#include<errno.h>#include<libio.h>

DESCRIPTION

The libaio library 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.
These functions are part of the library with realtime functions named
libaiolibc binary. The implementation of these functions can be done
using support in the kernel.
All IO 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
structiocb It is defined in libio.h as follows.
typedef struct io_context *io_context_t;
typedef enum io_iocb_cmd {
IO_CMD_PREAD = 0,
IO_CMD_PWRITE = 1,
IO_CMD_FSYNC = 2,
IO_CMD_FDSYNC = 3,
IO_CMD_POLL = 5,
IO_CMD_NOOP = 6,
} io_iocb_cmd_t;
struct io_iocb_common {
void *buf;
unsigned __pad1;
long nbytes;
unsigned __pad2;
long long offset;
long long __pad3, __pad4;
}; /* result code is the amount read or -’ve errno */
struct iocb {
void *data;
unsigned key;
short aio_lio_opcode;
short aio_reqprio;
int aio_fildes;
union {
struct io_iocb_common c;
struct io_iocb_vector v;
struct io_iocb_poll poll;
struct io_iocb_sockaddr saddr;
} u;
};
intaio_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 IO
operations on devices like terminals where an lseek call would
lead to an error.
longu.c.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.
void*buf
This is a pointer to the buffer with the data to be written or
the place where the read data is stored.
longu.c.nbytes
This element specifies the length of the buffer pointed to by
io_bufintaio_reqprio
Is not currently used.
IO_CMD_PREAD
Start a read operation. Read from the file at position
u.c.offset and store the next u.c.nbytes bytes in the buffer
pointed to by bufIO_CMD_PWRITE
Start a write operation. Write u.c.nbytes bytes starting at buf
into the file starting at position u.c.offsetIO_CMD_NOP
Do nothing for this control block. This value is useful
sometimes when an array of structiocb values contains holes,
i.e., some of the values must not be handled although the whole
array is presented to the io_submit function.
IO_CMD_FSYNCIO_CMD_POLL
This is experimental.