iob_write(3)
π iob_write(3) β from the Library Functions Manual, bestie π
okay so. you found the page for iob_write, and honestly? it's giving "quietly the most important function in your SSL stack." let's get into it π«Ά
β¨ NAME β¨
iob_write β send I/O batch through callback
like, that's the whole vibe. batch goes in, callback gets called, bytes come out. π
πΈ SYNTAX πΈ
#include <libowfat/iob.h>
typedef int64 (*io_write_callback)(int64 s,const void* buf,uint64 n);
int64 iob_write(int64 s,io_batch* b,io_write_callback cb);
there it is. one include, one typedef, one function. clean. no notes. β¨
π¦ DESCRIPTION π¦
so iob_write takes your batch b β the rest of it, specifically β and sends it through the callback cb, passing s along as the first argument. and cb? it's expected to behave like io_trywrite(2). no cap.
this interface is made for sending an I/O batch through a filter β like if you wanna encrypt it or compress it before it goes anywhere. so cute, so useful. π but if you literally just wanna yeet an I/O batch at a socket, that's not this. that's iob_send, bestie. use that one.
now the return values, and you need to know these because they're basically the plot of the whole function:
- it returns the number of bytes written π₯³
0β there were no more bytes to be written in the batch, we're done-1β that'sEAGAIN, we gotta wait-3β a permanent error, like for example"connection reset by peer"π
the normal usage pattern, iykyk: use io_wait to figure out when a descriptor is actually writable, and then just call iob_write over and over until it returns 0, -1, or -3. that's the loop. that's the whole thing.
and then, depending on what it gave you:
- returned
0β terminate the loop, everything was written OK π - returned
-1β callio_waitagain, we're just waiting on the vibe - returned
-3β signal an error, bestie, it's over π
the callback is supposed to behave like write(2), which means: return the number of bytes written, return 0 for EOF, return -1 for error (and heads up β iob_write will return -3 then). and if you're doing non-blocking I/O and you need to wait for the next write event, return -1 with errno==EAGAIN. when that happens, iob_write will return -1. teamwork, honestly. π«Ά
π NOTE π
listen up because this one bites people π
iob_write will keep calling your callback until it returns an error. like, it does not get tired. it does not get bored. it will just keep going.
so if you're in a state machine β say, a web server using this for SSL support β make sure you write at most n bytes at a time (e.g. 64k), and the next time you're called, return -1. otherwise iob_write might not return until the whole file is served. π not a fun way to find out. protect your event loop, girl.
π SEE ALSO π
and that's the page!! πβ¨ this one came from the Library Functions Manual, and the footer's just sitting there being all iob_write(3) at you. no date, no version drama, just the name and the manual, keeping it iconic. periodt. ππΈ
π¦ 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