aio_read

Date:

10-20-2011

NAME

aio_read - Asynchronous I/O read

SYNOPSIS

#include <aio.h>

int aio_read(aiocb_t *aiocbp);

DESCRIPTION

The aio_read function allows the calling process to read aiocbp->aio_nbytes from the file associated with aiocbp->aio_fildes, at the file offset aiocbp->aio_offset, into the buffer pointed to by aiocbp->aio_buf (see read). The function call returns when the read request has been initiated or, at a minimum, queued for the file or device.

The aiocb->aio_sigevent defines how the calling process will be notified upon I/O completion.

If sigev_notify is SIGEV_NONE, then no notification will be posted to the calling application.

If sigev_notify is SIGEV_SIGNAL, then the signal specified in sigev_signo will be sent to the calling process. If SA_SIGINFO is set for the signal (see sigaction), then the signal will be queued to the process and the value in sigev_value will be the si_value in the generated signal.

(Deferred implementation) If sigev_notify is SIGEV_CALLBACK then the function sigev_func will be called with sigev_value as the argument. Only one callback will be called at a time, however programs should be careful to note that a callback may be run in parallel with the calling process.

(Deferred implementation) If sigev_notify is SIGEV_THREAD then the function sigev_notify_function will be called by a new thread (see pthreads) with sigev_value as the argument. This thread is created when the event arrives with the attributes specified in sigev_notify_attributes except that it is automatically detached. The calling process should ensure there are sufficient resources to create the thread.

All aio_read calls must supply a complete aiocb->aio_sigevent structure.

The aiocbp->aio_lio_opcode field is ignored by aio_read.

Prioritized I/O is not currently supported among asynchronous file operations. aiocbp->aio_reqprio will be ignored.

After a call to aio_read, the aiocbp may be used as an argument to aio_error and aio_return to determine the error status and return status, respectively, of the asynchronous operation while it is proceeding. If an error condition is encountered during queueing, the function call returns without having initiated or queued the request. After a successful call to enqueue an asynchronous I/O operation, the value of the file offset for the file is undefined.

If the buffer pointed to by aiocbp->aio_buf or the control block pointed to by aiocbp changes or becomes an illegal address prior to asynchronous I/O completion, then the behavior is undefined. Simultaneous asynchronous operations using the same aiocbp produce undefined results.

For any system action that changes the process memory space while an asynchronous I/O is outstanding to the address range being changed, the result of that asynchronous I/O is undefined.

RETURN VALUES

The aio_read function returns the value 0 to the calling process if the I/O operation is successfully queued; otherwise, the function returns the value -1 and sets errno to indicate the error.

EAGAIN

The requested asynchronous I/O operation was not queued due to library or system resource limitations. This is due to exceeding the maximum number of outstanding asynchronous I/O operations for the library or system. The library limit can be increased with aio_init. The system maximum can be checked with a call to sysconf with an argument of _SC_AIO_MAX.

Each of the following conditions may be detected synchronously at the time of the call to aio_read, or asynchronously. If any of the conditions below are detected synchronously at the time of the call, the aio_read function shall return -1 and set errno to the corresponding value. If any of the conditions below are detected asynchronously, the return status of the asynchronous operation shall be set to -1 and the error status of the asynchronous operation shall be set to the corresponding value.

EBADF

The aiocbp->aio_fildes argument is not a valid file descriptor open for reading.

EINVAL

The file offset value implied by aiocbp->aio_offset would be invalid, sigenv_notify is an invalid value, or aiocbp->aio_nbytes is an invalid value.

In the case that aio_read successfully queues the I/O operation, the return status of the asynchronous operation will be one of the values normally returned by the read function call. If the operation is successfully queued, but is subsequently canceled or encounters an error, the error status for the asynchronous operation shall contain one of the values normally set by the read function call or the following:

ECANCELED

The requested I/O was canceled before the I/O completed due to an explicit aio_cancel() request.

SEE ALSO

aio_error(3c), aio_cancel(3c), aio_fsync(3c), aio_init(3c), aio_return(3c), aio_write(3c), lio_listio(3c), sysconf(3c)

read(2)