select(3N) — NETWORK FUNCTIONS
NAME
select − synchronous I/O multiplexing
SYNOPSIS
#include <sys/time.h>
#include <sys/types.h>
select(int nfds, fd_set ∗readfds, fd_set ∗writefds, fd_set ∗exceptfds, struct
timeval ∗timeout);
FD_SET(int fd, fd_set ∗fdset);
FD_CLR(int fd, fd_set ∗fdset);
FD_ISSET(int fd, fd_set ∗fdset);
FD_ZERO(fd_set ∗fdset);
DESCRIPTION
select examines the I/O descriptor sets whose addresses are passed in readfds, writefds, and exceptfds to see if any of their descriptors are ready for reading, are ready for writing, or have an exceptional condition pending, respectively. nfds is the number of bits to be checked in each bit mask that represents a file descriptor; the descriptors from 0 to nfds−1 in the descriptor sets are examined. On return, select replaces the given descriptor sets with subsets consisting of those descriptors that are ready for the requested operation.
The descriptor sets are stored as bit fields in arrays of integers. The following macros are provided for manipulating such descriptor sets: FD_ZERO(&fdset) initializes a descriptor set fdset to the null set. FD_SET(fd, &fdset) includes a particular descriptor fd in fdset. FD_CLR(fd, &fdset) removes fd from fdset. FD_ISSET(fd, &fdset) is nonzero if fd is a member of fdset, zero otherwise. The behavior of these macros is undefined if a descriptor value is less than zero or greater than or equal to FD_SETSIZE. FD_SETSIZE is a constant defined in sys/select.h (included by sys/types.h) and is normally at least equal to the maximum number of descriptors supported by the system.
If timeout is not a NULL pointer, it specifies a maximum interval to wait for the selection to complete. If timeout is a NULL pointer, the select blocks indefinitely. To effect a poll, the timeout argument should be a non-NULL pointer, pointing to a zero-valued timeval structure.
Any of readfds, writefds, and exceptfds may be given as NULL pointers if no descriptors are of interest.
RETURN VALUE
select returns one of the following quantities:
o M88000 only: number of ready readfds descriptors + number of ready writefds descriptors + number of ready exceptfds descriptors.
o M68000 only: number of ready readfds descriptors + number of ready writefds descriptors + number of ready exceptfds descriptors - number of descriptors ready for both reading and writing.
o 0 if the time limit expired.
o −1 if an error occurred.
Unless select returns −1, select replaces the given descriptor sets with subsets consisting of those descriptors that are ready for the requested operation.
ERRORS
An error return from select indicates:
EBADF One of the I/O descriptor sets specified an invalid I/O descriptor.
EFAULT readfds, writefds, exceptfds or timeout point to an invalid portion of the process address space. (M88000 only)
EINTR A signal was delivered before any of the selected events occurred, and before the time limit expired.
EINVAL A component of the pointed-to time limit is outside the acceptable range: t_sec must be between 0 and 108, inclusive. t_usec must be greater-than or equal to 0, and less than 106.
ENOPKG The socket family of networking system calls is not configured into the kernel.
SEE ALSO
NOTES
The default value for FD_SETSIZE (currently 1024) is larger than the default limit on the number of open files. In order to accommodate programs that may use a larger number of open files with select, it is possible to increase this size within a program by providing a larger definition of FD_SETSIZE before the inclusion of <sys/types.h>.
In future versions of the system, select may return the time remaining from the original timeout, if any, by modifying the time value in place. It is thus unwise to assume that the timeout value will be unmodified by the select call.
The M88000 select as defined by the M88000 Processor Specific ABI emulates BSD select functionality and therefore differs slightly in behavior from the original SVR4 based M68000 select.
select(3N) is part of the socket family of networking system calls. Some kernels may not include the networking system calls, in which case select(3N) is not available. For arbitrary file descriptors, poll(2) is recommended.