io_tryread(3)
π io_tryread β NAME π
okay bestie, welcome to io_tryread(3) from the Library Functions Manual β it's the "read from a descriptor without blocking" girlie π
β¨ SYNTAX β¨
#include <libowfat/io.h>
int io_tryread(int64 fd,char* buf,int64 len);
π¦ DESCRIPTION π¦
so like, io_tryread tries to read len bytes of data from descriptor fd into buf[0], buf[1], ..., buf[len-1]. that's the whole vibe. π«Ά
β οΈ but real talk β the effects are undefined if len is 0 or smaller. don't do that. that's not the moment. π
and because nothing in life is ever just one outcome, there are several possible results, bestie:
o_tryreadreturns an integer between 1 andlenβ that's how many bytes were available for immediate reading, and they got read into the beginning ofbuf. NOTE: this number can be, and often is, smaller thanlen. so do not assumeio_tryreadalways succeeds in reading exactlylenbytes. it said what it said. πio_tryreadreturns 0 β no bytes were read because the descriptor is at end of file. like, this descriptor hit the end of a disk file, or it's reading an empty pipe that's been closed by all writers. it's giving "we're done here." β¨io_tryreadreturns -1, settingerrnotoEAGAINβ no bytes were read because the descriptor is not ready. for example, the descriptor is reading an empty pipe that could still be written to. it's not over, it's just not now. πio_tryreadreturns -3, settingerrnoto something other thanEAGAINβ no bytes were read because the read attempt encountered a persistent error. like a serious disk failure (EIO), an unreachable network (ENETUNREACH), or an invalid descriptor number (EBADF). that's a real problem, not a mood. π
io_tryread does not pause waiting for a descriptor that is not ready. it has places to be. if you want to pause, use io_waitread or io_wait instead. πΈ
and ooh β you can make io_tryread faster and more efficient by making the socket non-blocking with io_nonblock(). iconic optimization behavior, honestly. π₯
π SEE ALSO π
and that's the page bestie!! π mwah π this was io_tryread(3) β go forth and read non-blockingly, you got this πβ¨
π¦ where this page comes from
- alpine 3.24: libowfat-doc 0.34-r0 Β· GPL-2.0-only
- debian bookworm: libowfat-dev 0.32-4 Β· GPL-2.0-only
- debian trixie: libowfat-dev 0.32-5 Β· GPL-2.0-only
- nixos 26.05: libowfat 0.34
- nixpkgs unstable: libowfat 0.34
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- ubuntu noble: libowfat-dev 0.32-4.1build1 Β· GPL-2.0-only
- ubuntu questing: libowfat-dev 0.32-5
- ubuntu resolute: libowfat-dev 0.34-2 Β· GPL-2.0-only
- ubuntu stonking: libowfat-dev 0.34-2 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms