io_nonblock(3)
β¨ NAME β¨
io_nonblock β switch to non-blocking I/O, bestie π
π¦ SYNTAX π¦
#include <libowfat/io.h>
void io_nonblock(int64 fd);
π DESCRIPTION π
okay so picture this: io_nonblock takes your UNIX descriptor fd and puts it into ``non-blocking mode.'' That's it. That's the whole job. And the move here is that if you call io_nonblock(fd) before you call io_fd(fd), then io_tryread and io_trywrite get to be faster and more efficient. like, noticeably. it's giving optimization. π₯
but now the tea β β actually, current UNIX kernels do not support non-blocking descriptors. They support non-blocking open files. And on top of that, a whole lot of programs will straight up break if they bump into non-blocking mode. so the rule is: you must not use io_nonblock on a descriptor that you inherited from another program. no cap, that's a "do not do this" situation. π«
io_nonblock has no return value and it always succeeds β it never fails, it never gives you bad news, it just vibes. π And if d is not the number of a UNIX descriptor, then io_nonblock has no effect at all. nothing happens. it's fine.
π the blocking-mode contortions (aka the struggle)
if io_fd gets handed a descriptor that's in blocking mode, then io_tryread and io_trywrite have to go through the following whole entire ordeal to avoid blocking. it's not cute. it's giving survival mode. π
- Stop if
pollsays that the descriptor is not ready. Otherwise there's a good chance β but not a guarantee β because even ifpollsays the descriptor is ready, the descriptor might not be ready a moment later. (and also,pollcan fail on some systems. π) - Catch
SIGALRM.</color> And heads up:SIGALRMmust not be blocked, and it must not be used elsewhere in the program. so like... that signal is spoken for. don't touch it. π - Set an interval timer so that any blocking call will get interrupted by
SIGALRMwithin 10 milliseconds. (current UNIX kernels do not allow any shorter interval β that's literally the floor.) Of course, this may still mean a 10-millisecond delay. yeah. ten whole milliseconds. in computer time that's basically a century. π
π the easy path
if io_fd is given a descriptor in non-blocking mode (or a descriptor for a regular disk file), then io_tryread and io_trywrite get to avoid these contortions entirely. no signals, no timers, no drama. main character energy only. β
π SEE ALSO π
that's the whole page, babe π«Ά this has been io_nonblock(3) from the Library Functions Manual β go forth and be non-blocking, 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