io_setcookie(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 πŸ’–

okay bestie, this is io_setcookie(3) from the Library Functions Manual. The name says it all: io_setcookie β€” associate cookie with descriptor. ✨

✨ SYNTAX ✨

#include <libowfat/io.h>

void io_setcookie(int64 fd,void* cookie);

πŸ“ DESCRIPTION πŸ“

so io_setcookie is giving β€œattach a cookie to this descriptor.” And by cookie we mean a pointer to some anonymous data structure β€” not a snack, sadly. You can only have one cookie associated with a descriptor. One descriptor, one cookie, periodt. πŸ’…

When you wanna retrieve that cookie for a descriptor, you use io_getcookie(3) β€” usually right after io_canread or io_canwrite brought it to your attention. Like, β€œhey bestie, this fd is ready,” and you’re like β€œsay less, lemme grab my cookie.” πŸͺ

⚠️ important caveat, no cap: io_close does not deallocate your cookie. Not even a little. You need to do that yourself. The library is not your mom. 😭

The whole idea is iconic: you put the state associated with a TCP connection you serve into a common struct. Then you do not need to have your own data structure to retrieve the state for a connection β€” you can just use the data structure io_wait already maintains. The lookup works in constant time and should not cause any cache misses. It’s giving efficient, it’s giving main character energy. πŸ‘‘

🌈 SEE ALSO 🌈


β€” io_setcookie(3) from the Library Functions Manual. The footer is just the page title, no source, version, or date listed, so that’s the whole sign-off vibe. Mwah πŸ’‹πŸ¦‹