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 |
|---|---|
| Asynchronously reads some data from a file |
| Asynchronously writes some data into a file |
| Requests a flush operation for all outstanding asynchronous I/O operations (does not block) |
| Gets the error code for an outstanding asynchronous I/O operation |
| Gets the return code for a completed asynchronous I/O operation |
| Cancels an outstanding asynchronous I/O operation |
| 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_fildesThe file descriptor of the file (as returned by the
open( )system call) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access