---
name: "io_setcookie"
section: "3"
platform: "linux"
package: "libowfat-dev"
version: "0.32-5"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/io_setcookie"
---

# io\_setcookie(3)

associate cookie with descriptor

## NAME

io\_setcookie - associate cookie with descriptor

## SYNTAX

**#include \<libowfat/io.h\>**

void **io\_setcookie**(int64 fd,void\* cookie);

## DESCRIPTION

io\_setcookie associates a cookie (pointer to some anonymous data structure) with this descriptor.  Only one cookie can be associated with a descriptor.

Use [io\_getcookie(3)](/io_getcookie/3.md) to retrieve the cookie for a descriptor (usually after io\_canread or io\_canwrite brought it to your attention).

Please note that io\_close does not deallocate your cookie.  You need to do that yourself.

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 lookup works in constant time and should not cause any cache misses.

## SEE ALSO

[io\_wait(3)](/io_wait/3.md), [io\_getcookie(3)](/io_getcookie/3.md)
