Manual page for select(3C)
select - synchronous I/O multiplexing
SYNOPSIS
#include <sys/time.h>
#include <sys/types.h>
int select(int nfds,
fd_set *readfds,
fd_set *writefds,
fd_set *exceptfds,
struct timeval *timeout);
void FD_SET(int fd,
fd_set &fdset);
void FD_CLR(int fd,
fd_set &fdset);
int FD_ISSET(int fd,
fd_set &fdset);
void FD_ZERO(fd_set &fdset);
MT-LEVEL
MT-Safe
DESCRIPTION
select()
examines the I/O file descriptor sets whose addresses are passed in
readfds,
writefds,
and
exceptfds
to see if any of their file descriptors are ready for reading,
are ready for writing,
or have an exceptional condition pending, respectively.
Out-of-band data is the only exceptional condition.
nfds
is the number of bits to be checked in each bit mask that
represents a file descriptor; the file descriptors
from 0 to nfds -1 in the file descriptor sets are examined.
On return,
select()
replaces the given file descriptor sets with subsets consisting of
those file descriptors that are ready for the requested operation.
The return value from the call to
select()
is the number
of ready file descriptors.
The file descriptor sets are stored as bit fields in arrays of integers.
The following macros are provided for manipulating such file descriptor
sets:
FD_ZERO()
initializes a file descriptor set
fdset
to the null set.
FD_SET()
includes a particular file descriptor
fd in fdset.
FD_CLR()
removes
fd from fdset.
FD_ISSET()
is nonzero if
fd
is a member of
fdset,
zero otherwise.
The behavior of these macros is undefined if a
file descriptor value is less than zero or greater than or equal to
FD_SETSIZE.
FD_SETSIZE
is a constant defined in <sys/select.h>.
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 file descriptors are of interest.
RETURN VALUES
select()
returns the number of ready file descriptors contained in
the file descriptor sets
or -1 if an error occurred.
If the time limit expires, then
select()
returns 0.
ERRORS
The call fails if:
- EBADF
-
One of the I/O file descriptor sets specified an invalid I/O file descriptor.
- EINTR
-
A signal was delivered before any of the
selected events occurred, or 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
10,
inclusive.
t_usec
must be greater than or equal to 0, and less than
10.
SEE ALSO
poll.2
read.2
write.2
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>.
The file descriptor sets are always modified on return, even
if the call returns as the result of a timeout.
Created by unroff & hp-tools.
© by Hans-Peter Bischof. All Rights Reserved (1997).
Last modified 21/April/97