io_fd - prepare descriptor for io_wait

NAME  SYNTAX  DESCRIPTION  RETURN VALUE  SEE ALSO 

NAME

io_fd − prepare descriptor for io_wait

SYNTAX

#include <libowfat/io.h>

int io_fd(int64 fd);

DESCRIPTION

If you want to use io_canread() and io_canwrite() on a descriptor, you have to use io_wait() on it first, and io_wait() has to know which descriptors you are interested in. io_fd() informs io_wait() that you are interested in this fd.

If you know that the descriptor is writable, call io_fd_canwrite() instead. Most fresh descriptors are writable, e.g. if it came from pipe(2) or socketpair(2) or accept(2). This will save one syscall.

io_pipe and io_socketpair already call io_fd_canwrite() for you.

Waiting on descriptors only works for sockets, fifos and pipes. It may also work on devices and TTYs, but that is platform dependent -- you should not rely on that. It does not work on files.

RETURN VALUE

io_fd returns 1 on success, 0 on error.

SEE ALSO

io_fd_canwrite(3), io_wait(3), io_wantread(3), io_canread(3), io_eagain(3), io_nonblock(3)


Updated 2024-01-29 - jenkler.se | uex.se