iob_init(3)

✨ iob_init(3) ✨

okay bestie, sit down, hydrate, and let me tell you about iob_init_autofree from the Library Functions Manual πŸ’– this is the lil function that sets up a whole new I/O batch for you, with the autofree flag already flipped on. main character energy fr fr πŸŽ€


🌸 NAME 🌸

iob_init_autofree β€” initialize a new I/O batch, but make it autofree πŸ’…


πŸ¦‹ SYNTAX πŸ¦‹

#include <libowfat/iob.h>

int iob_init_autofree(io_batch* b,size_t hint_entries);

✨ DESCRIPTION ✨

So basically, iob_init_autofree initializes *b and allocates enough space for hint_entries entries, where an entry is a buffer or a file. 🫢

hint_entries is purely a performance hint, no cap. If you're not sure what number to give it, just pass 1 and move on with your day. iykyk 🌈

The autofree flag gets set by this one. That means your resources get freed inside iob_send once they've actually been sent out β€” not just when you finally call iob_reset or iob_free at the end. πŸ’€ but listen: you still have to call those. Autofree only frees the resources to be sent in the batch, not the resources of the batch itself. Two different things, don't get it twisted. πŸ™ˆ

You can add buffers, strings and files to an I/O batch and then send the whole thing at once with iob_send. one big slay, one go ✨

The whole point of the I/O batch API is that it exploits platform specific APIs, like FreeBSD's sendfile. πŸ‘‘

  • The file contents will always be sent in a way that lets the operating systems do zero copy TCP.
  • The buffers will always be sent using as few syscalls as possible, while avoiding unnecessary copying (using writev).

no cap, that's the vibe check it's passing πŸ’œ


πŸŽ€ RETURN VALUE πŸŽ€

  • iob_init returns 0 on success. ✨
  • If there was a memory allocation error, it returns -1 instead. 😭

πŸ’… SEE ALSO πŸ’…


okay that's the whole thing, you ate it πŸ“ this was iob_init(3) out of the Library Functions Manual, brought to you by the fine folks shipping libowfat. go forth and batch your I/O, bestie β€” periodt. πŸ’–πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from