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

Library Functions Manual · a libowfat moment ✨


✨ NAME ✨

io_getcookie β€” retrieve cookie πŸͺ


🌸 SYNTAX 🌸

#include <libowfat/io.h>

void* io_getcookie(int64 fd);

bestie it literally takes one arg and hands you a pointer, we love a low-effort queen πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

So io_getcookie retrieves a cookie β€” and by "cookie" we mean a pointer to some anonymous data structure you associated with this descriptor. It's giving secret lil treat for your fd, no cap πŸ’…

Wanna set one? Use io_setcookie(3) to associate a cookie with a descriptor. That's the whole pipeline, you put the cookie in, you get the cookie out 🫢

And if you did not associate a cookie with this descriptor, io_getcookie returns NULL. Like, respectfully, there was no cookie. Empty plate. Tragic but valid 😭

Now here's the actual galaxy-brain part, because this is the slay πŸ”₯ The idea is that you put the state associated with a TCP connection you serve in 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 way that this means zero extra bookkeeping on your end, we're obsessed fr fr 🌈

And the lookup itself? It works in constant time and should not cause any cache misses. The performance is genuinely iconic, no notes ⭐

ngl this is the part where you stop writing your own lookup table and just let io_wait carry the whole thing, main character energy πŸ’œ

🌈 SEE ALSO 🌈

go read io_setcookie(3) next so you actually have a cookie to get, iykyk πŸŽ€


okay that's the whole page bestie, ty for reading, mwah πŸ’– this was the io_getcookie(3) entry from the Library Functions Manual, brought to you by libowfat, and yes the footer is literally just io_getcookie(3) again because manpages are dramatic like that πŸ’…βœ¨