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

# io\_nonblock(3)

switch to non-blocking I/O

## NAME

io\_nonblock - switch to non-blocking I/O

## SYNTAX

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

void **io\_nonblock**(int64 fd);

## DESCRIPTION

io\_nonblock puts UNIX descriptor fd into \`\`non-blocking mode.'' Calling io\_nonblock(*fd*) before io\_fd(*fd*) makes io\_tryread and io\_trywrite faster and more efficient.

Actually, current UNIX kernels do not support non-blocking descriptors; they support non-blocking open files. Furthermore, many programs will break if they encounter non-blocking mode. This means that you must not use io\_nonblock for a descriptor inherited from another program.

io\_nonblock has no return value; it always succeeds. If d is not the number of a UNIX descriptor, io\_nonblock has no effect.

If io\_fd is given a descriptor in blocking mode, io\_tryread and io\_trywrite go through the following contortions to avoid blocking:

- 1

  Stop if poll says that the descriptor is not ready. Otherwise there's a good chance, but not a guarantee: even if poll says the descriptor is ready, the descriptor might not be ready a moment later. (Furthermore, poll can fail on some systems.)

- 2

  Catch SIGALRM. SIGALRM must not be blocked, and must not be used elsewhere in the program.

- 3

  Set an interval timer so that any blocking call will be interrupted by SIGALRM within 10 milliseconds. (Current UNIX kernels do not allow any shorter interval.) Of course, this may still mean a 10-millisecond delay.

If io\_fd is given a descriptor in non-blocking mode (or a descriptor for a regular disk file), io\_tryread and io\_trywrite avoid these contortions.

## SEE ALSO

[io\_wait(3)](/io_wait/3.md), [io\_canwrite(3)](/io_canwrite/3.md)
