io_canwrite(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

πŸ’– NAME πŸ’–

io_canwrite β€” bestie, this one hands you a file descriptor that's ready to be written to ✨


πŸŽ€ SYNTAX πŸŽ€

#include <libowfat/io.h>

int64 io_canwrite();

🌸 DESCRIPTION 🌸

okay so io_canwrite returns the next file descriptor that can be written to. that's the whole vibe. 🫢

but like… there are prerequisites, bestie, it's not just gonna hand you fds for free:

  • you have to have used io_wantwrite() on that file descriptor earlier
  • and you have to have called io_wait() or io_waituntil()

when you do that, these functions keep an internal data structure of which descriptors the operating system reported as writable. lowkey iconic bookkeeping ngl πŸ’…

🚨 IMPORTANT REALITY CHECK 🚨 there is no guarantee that you can still write data to that descriptor without blocking β€” only that you could back when io_wait() or io_waituntil() were called. another process could have written something before you got there. the way that timing works is so rude 😭 so look at the result from io_trywrite().

if there are no more descriptors that you can write to without blocking, io_canwrite will return -1. and when that happens? you should call io_wait() or io_waituntil() again. go around the loop one more time, bestie, it's giving carousel 🎠

and now the rules of engagement, fr fr:

⚠️ you should only use io_trywrite(3), io_sendfile(3) or iob_send(3) to write to the file. not plain write(2). if you do use write(2) and get EAGAIN, call io_eagain(3). periodt. πŸŽ€

πŸ¦‹ SEE ALSO πŸ¦‹


and that's the page, bestie!! 🫢✨ this one's from the Library Functions Manual, and the page itself is io_canwrite(3) β€” no version or date to speak of, it's just out here living its truth πŸ’… mwah, go write some fds responsibly πŸŽ€πŸ¦‹