HP-UX Reference (11i v2 07/12) - 2 System Calls (vol 5)

s
select(2) select(2)
NAME
select(), FD_CLR(), FD_ISSET(), FD_SET(), FD_ZERO() - synchronous I/O multiplexing
SYNOPSIS
#include <sys/time.h>
int select(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *errorfds, struct timeval *timeout);
void FD_CLR(int fd, fd_set *fdset);
int FD_ISSET(int fd, fd_set *fdset);
void FD_SET(int fd, fd_set *fdset);
void FD_ZERO(fd_set *fdset);
For Backward Compatibility Only: (_XOPEN_SOURCE_EXTENDED not defined)
#include <time.h>
int select(size_t nfds, int *readfds, int *writefds,
int *exceptds, const struct timeval *timeout);
DESCRIPTION
The select() function indicates which of the specified file descriptors is ready for reading, ready for
writing, or has an error condition pending. If the specified condition is false for all of the specified file
descriptors, select() blocks, up to the specified timeout interval, until the specified condition is true for
at least one of the specified file descriptors.
The select() function supports regular files, terminal and pseudo-terminal devices, STREAMS-based
files, FIFOs and pipes. The behaviour of select() on file descriptors that refer to other types of file is
unspecified.
The nfds argument specifies the range of le descriptors to be tested. The select()
function tests file
descriptors in the range of 0 to nfds -1. File descriptor f is represented by the bit 1<<f in the masks. More
formally, a file descriptor is represented by:
fds[(f / BITS_PER_INT)] & (1 << (f % BITS_PER_INT))
If the readfds argument is not a null pointer, it points to an object of type fd_set that on input specifies the
file descriptors to be checked for being ready to read, and on output indicates which file descriptors are
ready to read.
If the writefds argument is not a null pointer, it points to an object of type fd_set that on input specifies the
file descriptors to be checked for being ready to write, and on output indicates which file descriptors are
ready to write.
If the errorfds argument is not a null pointer, it points to an object of type fd_set that on input specifies the
file descriptors to be checked for error conditions pending, and on output indicates which le descriptors
have error conditions pending.
On successful completion, the objects pointed to by the readfds, writefds, and errorfds arguments are
modified to indicate which file descriptors are ready for reading, ready for writing, or have an error condi-
tion pending, respectively. For each file descriptor less than nfds, the corresponding bit will be set on suc-
cessful completion if it was set on input and the associated condition is true for that file descriptor.
If the timeout argument is not a null pointer, it points to an object of type structtimeval that specifies a
maximum interval to wait for the selection to complete. If the timeout argument points to an object of type
structtimeval whose members are 0,
select() does not block. If the timeout argument is a null pointer,
select() blocks until an event causes one of the masks to be returned with a valid (non-zero) value. If
the time limit expires before any event occurs that would cause one of the masks to be set to a non-zero
value, select() completes successfully and returns 0.
Implementations may place limitations on the maximum timeout interval supported. On all implementa-
tions, the maximum timeout interval supported will be at least 31 days. If the timeout argument specifies
a timeout interval greater than the implementation- dependent maximum value, the maximum value will
be used as the actual timeout value. Implementations may also place limitations on the granularity of
timeout intervals. If the requested timeout interval requires a finer granularity than the implementation
supports, the actual timeout interval will be rounded up to the next supported value.
HP-UX 11i Version 2: December 2007 Update 1 Hewlett-Packard Company 337