|
select()
examines the I/O descriptor sets whose addresses are passed in
readfds, writefds, and
exceptfds to see if some of their descriptors
are ready for reading, ready for writing, or have an exceptional
condition pending.
width is the number of bits to be checked in each bit mask that represent a file
descriptor;
the descriptors from 0 through
width-1 in the descriptor sets are examined.
Typically
width has the value returned by
ulimit(3C) for the maximum number of file descriptors.
On return,
select()
replaces the given descriptor sets
with subsets consisting of those descriptors that are ready
for the requested operation.
The total number of ready descriptors in all the sets is returned.
The descriptor sets are stored as bit fields in arrays of integers.
The following macros are provided for manipulating such descriptor sets:
FD_ZERO
initializes a descriptor set
fdset to the null set.
FD_SET(fd, &fdset ) includes a particular
descriptor
fd in
fdset. FD_CLRfP(fd, &fdset )
removes
fd from
fdset. FD_ISSETfP(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, which 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.
Selecting true for reading on a socket descriptor upon which a
listen(2) call has been performed indicates that a subsequent
accept(2) call on that descriptor will not block.
|