select(2) — 4 BSD
NAME
select − synchronous i/o multiplexing
SYNOPSIS
#include <sys/types.h>
#include <sys/time.h>
nfound = select (nfds, readfds, writefds, execptfds, timeout)
int nfound;
unsigned int nfds;
fd_set ∗readfds, ∗writefds, ∗execptfds;
struct timeval ∗timeout;
DESCRIPTION
select examines the i/o descriptor sets whose addresses are passed in readfds, writefds, and execptfds to see if some of their descriptors are ready for reading, writing, or have an exceptional condition pending, respectively.
The first nfds descriptors are checked in each set, i.e., the descriptors from 0 through nfds-1 in the descriptor sets are examined. On return, select replaces the value of each descriptor set with subsets consisting of those descriptors that are ready for the requested operation. The total number of ready descriptors is returned in nfound.
The descriptors are stored as bit positions in arrays of integers. The first integer in the array is used to represent the file descriptors in the range 0-31 with bit positions 0-31, respectively. The type fd_set, defined in <sys/types.h> is used for these bit arrays. The following macros are used to manipulate descriptor sets:
FD_ZERO(p) Clear all bits in descriptor set p. This operation should be performed on each descriptor set before any other use.
FD_SET(f, p) Set the bit in descriptor set p corresponding to a file descriptor f.
FD_CLR(f, p) Clear the bit in descriptor set p corresponding to a file descriptor f.
FD_ISSET(f, p) Test the bit in descriptor set p corresponding to a file descriptor f and evaluate to true if it is set, false if it is not set.
If timeout is a non-zero pointer, it specifies a maximum interval to wait for the selection to complete. If timeout is a zero pointer, the select blocks indefinitely. To affect a poll, the timeout argument should be non-zero, pointing to a zero valued timeval structure.
Any of readfds, writefds, and execptfds may be given as NULL pointers if no descriptors are of interest.
RETURN VALUE
select returns the number of descriptors which are contained in the bit masks, or −1 if an error occurred. If the time limit expires then select returns 0.
ERRORS
An error return from select indicates:
[EBADF] One of the bit masks specified an invalid descriptor.
[EINTR] A signal was delivered before any of the selected for events occurred or the time limit expired.
NOTE
This call is defined in the 88open Binary and Object Compatibility Standards’ Networking Supplements (BCSNS and OCSNS) for use in BCS/OCS compliant networking applications. OCS/OCSNS-defined functions may be accessed by passing OCS options to cc(1) and ld(1).
SEE ALSO
accept(2), connect(2), read(2), write(2), recv(2), send(2)
BUGS
The descriptor masks are always modified on return, even if the call returns as the result of the timeout.
CX/UX Programmer’s Reference Manual