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, 0 is returned โœจ
  • on error, the request is not enqueued, -1 is returned, and errno gets 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_fildes is not a valid file descriptor open for reading. not it. ๐Ÿ™…โ™€๏ธ
  • EINVAL โ€” one or more of aio_offset, aio_reqprio, or aio_nbytes are 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.1
  • POSIX.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 aiocb structure 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
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms