O'Reilly logo

Understanding the Linux Kernel, 3rd Edition by Marco Cesati, Daniel P. Bovet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Asynchronous I/O

The POSIX 1003.1 standard defines a set of library functions—listed in Table 16-4—for accessing the files in an asynchronous way. "Asynchronous" essentially means that when a User Mode process invokes a library function to read or write a file, the function terminates as soon as the read or write operation has been enqueued, possibly even before the actual I/O data transfer takes place. The calling process can thus continue its execution while the data is being transferred.

Table 16-4. The POSIX library functions for asynchronous I/O

Function

Description

aio_read( )

Asynchronously reads some data from a file

aio_write( )

Asynchronously writes some data into a file

aio_fsync( )

Requests a flush operation for all outstanding asynchronous I/O operations (does not block)

aio_error( )

Gets the error code for an outstanding asynchronous I/O operation

aio_return( )

Gets the return code for a completed asynchronous I/O operation

aio_cancel( )

Cancels an outstanding asynchronous I/O operation

aio_suspend( )

Suspends the process until at least one of several outstanding I/O operations completes

Using asynchronous I/O is quite simple. The application opens the file by means of the usual open( ) system call. Then, it fills up a control block of type struct aiocb with the information describing the requested operation. The most commonly used fields of the struct aiocb control block are:

aio_fildes

The file descriptor of the file (as returned by the open( ) system call) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required