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

# iob\_write(3)

send I/O batch through callback

## NAME

iob\_write - send I/O batch through callback

## SYNTAX

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

typedef int64 (\*io\_write\_callback)(int64 s,const void\* buf,uint64 n);

int64 **iob\_write**(int64 s,io\_batch\* b,io\_write\_callback cb);

## DESCRIPTION

iob\_write sends the (rest of) *b* through the callback *cb*, passing *s* as first argument.  *cb* is expected to behave like io\_trywrite(2).

This interface is intended to send an I/O batch through a filter, for example to encrypt or compress it.  If you just want to send an I/O batch to a socket, use iob\_send instead.

iob\_write returns the number of bytes written, 0 if there were no more bytes to be written in the batch, -1 for EAGAIN, or -3 for a permanent error (for example "connection reset by peer").

The normal usage pattern is using io\_wait to know when a descriptor is writable, and then calling iob\_write until it returns 0, -1 or -3.

If iob\_write returns 0, terminate the loop (everything was written OK).  If it returns -1, call io\_wait again.  If it returned -3, signal an error.

The callback is supposed to behave like [write(2)](/write/2.md), i.e. return the number of bytes written, 0 for EOF, -1 for error (iob\_write will return -3 then).  Return -1 with errno==EAGAIN if using non-blocking I/O when we need to wait for the next write event.  iob\_write will then return -1.

## NOTE

iob\_write will continue to call your callback until it returns an error. So if you are in a state machine, for example a web server using this for SSL support, make sure to write at most n bytes at a time (e.g. 64k) and the next time you are called return -1.  Otherwise iob\_write might not return until the whole file is served.

## SEE ALSO

[iob\_send(3)](/iob_send/3.md)
