io_setcookie(3)
π 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 ππ¦
π¦ 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