io_tryread(3)

πŸ“¦
version 0.34 Β· 2 versions
  • 0.34 Β· alpine 3.24, debian bookworm, debian trixie, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 0.30 Β· fedora 43, fedora 44, ubuntu jammy
, in alpine 3.24, debian bookworm, debian trixie, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– 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_tryread returns an integer between 1 and len β€” that's how many bytes were available for immediate reading, and they got read into the beginning of buf. NOTE: this number can be, and often is, smaller than len. so do not assume io_tryread always succeeds in reading exactly len bytes. it said what it said. 😭
  • io_tryread returns 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_tryread returns -1, setting errno to EAGAIN β€” 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_tryread returns -3, setting errno to something other than EAGAIN β€” 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 πŸ‘‘βœ¨