aio_read(3)
๐ aio_read โ asynchronous read ๐
okay bestie, welcome to the aio_read(3) page, from the Library Functions Manual โจ this one lives in the Real-time library (librt, link with -lrt) and it's literally the async girlboss version of read(2). let's get into it ๐ซถ
โจ SYNOPSIS โจ
#include <aio.h>
int aio_read(struct aiocb *aiocbp);
๐ธ DESCRIPTION ๐ธ
so basically, aio_read() queues up the I/O request that's described by the buffer that aiocbp points at. it's the asynchronous analog of read(2), no cap. the arguments of this call:
read(fd, buf, count)
correspond in order to the fields aio_fildes, aio_buf, and aio_nbytes of the structure that aiocbp points to. (if you wanna know what the aiocb structure even is, go peek at aio(7) ๐)
the data gets read starting at the absolute position aiocbp->aio_offset, completely regardless of the file offset. and after the call? the value of the file offset is unspecified. like, we don't know her. ๐คทโ๏ธ
the whole "asynchronous" thing means this call returns the second the request has been enqueued โ the read may or may not have completed by the time the call comes back. to test for completion you use aio_error(3). to get the return status of a completed I/O operation you use aio_return(3). and if you want asynchronous notification that the I/O finished, you set aiocbp->aio_sigevent appropriately โ full details are in sigevent(3type) ๐
if _POSIX_PRIORITIZED_IO is defined, and this file supports it, then the async operation gets submitted at a priority equal to the priority of the calling process minus aiocbp->aio_reqprio. math queen ๐งฎ
the field aiocbp->aio_lio_opcode is ignored. she's not invited to the party ๐
and no data is read from a regular file beyond its maximum offset. periodt.
๐ฅ RETURN VALUE ๐ฅ
- on success,
0is returned โจ - on error, the request is not enqueued,
-1is returned, anderrnogets set to indicate the error.
now if an error only gets detected later, it'll be reported through aio_return(3) (which returns status -1) and aio_error(3) (the error status โ literally whatever you would have gotten in errno, like EBADF). sneaky but that's the deal ๐ญ
๐ ERRORS ๐
EAGAINโ out of resources. bestie is tired. ๐ฎโ๐จEBADFโaio_fildesis not a valid file descriptor open for reading. not it. ๐ โ๏ธEINVALโ one or more ofaio_offset,aio_reqprio, oraio_nbytesare invalid. vibe check failed ๐ENOSYSโaio_read()is not implemented. she does not exist here, i fear ๐ปEOVERFLOWโ the file is a regular file, we start reading before end-of-file and want at least one byte, but the starting position is past the maximum offset for this file. that's giving off the map ๐บ๏ธ๐
๐ ATTRIBUTES ๐
for an explanation of the terms used in this section, see attributes(7).
- Interface:
aio_read() - Attribute: Thread safety
- Value:
MT-Safeโ
slay, she's thread safe, no notes ๐
โญ STANDARDS โญ
POSIX.1-2008. iconic behavior, honestly ๐
๐ฆ HISTORY ๐ฆ
glibc 2.1POSIX.1-2001
a true veteran of the game, we love a legacy queen ๐
๐ธ NOTES ๐ธ
okay listen up, this part is important so pay attention bestie:
- it's a good idea to zero out the control block before you use it. do it. ๐งผ
- the control block must not be changed while the read operation is in progress. hands off. โ
- the buffer area being read into must not be accessed during the operation โ or undefined results may occur. i'm serious, don't touch it ๐ญ
- the memory areas involved must remain valid. keep them alive, hydrate them, whatever ๐
- simultaneous I/O operations that specify the same
aiocbstructure produce undefined results. don't share, it's not cute ๐
no cap, these aren't suggestions. undefined results are the "we don't talk about it" of C programming. ๐
โจ EXAMPLES โจ
see aio(7) โ she's got the whole demo, iykyk ๐ง
๐ SEE ALSO ๐
aio_cancel(3), aio_error(3), aio_fsync(3), aio_return(3), aio_suspend(3), aio_write(3), lio_listio(3), aio(7)
and that's the whole page, bestie!! ๐ this one came from Linux man-pages 6.20, dated 2026-02-08, and the original title said aio_read(3) up top with the manual name Library Functions Manual. go queue some reads, stay async, and remember: don't touch the buffer mid-operation ๐โจ๐ซถ
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: GPL-2.0-or-later
- Copyright 2003, Andries E. Brouwer <aeb@cwi.nl>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms