SELECT(2) COMMAND REFERENCE SELECT(2)
NAME
select - synchronous I/O multiplexing
SYNOPSIS
#include <sys/time.h>
nfound = select(nfd, readfd, writefd, execptfd, timeout)
int nfound, nfd;
unsigned long readfd[], writefd[], execptfd[];
struct timeval *timeout;
DESCRIPTION
Select examines the I/O descriptors specified by the arrays
of bit masks readfd, writefd, and execptfd to see if they
are ready for reading, writing, or have an exceptional
condition pending, respectively. These mask arrays must be
at least as long as "(nfd+31)/32", or one element for every
32 file descriptors. File descriptor f is represented in
the mask by:
mask[f/32] |= 1 << (f % 32)
Nfd descriptors are checked, i.e. the bits from 0 through
nfd-1 in the masks are examined. Select returns, in place,
a mask of those descriptors which are ready. The total
number of ready descriptors is returned in nfound.
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
effect a poll, the timeout argument should be non-zero,
pointing to a zero-valued timeval structure.
Any of readfd, writefd, and execptfd may be given as 0 if no
descriptors are of interest.
DIAGNOSTICS
An error return from select indicates:
[EBADF] One of the bit masks specifies an invalid
descriptor.
[EINTR] An signal was delivered before any of the
selected-for events occurred or the time limit
expired.
[EINVAL] Timeout does not point to a reasonable value.
[EFAULT] An argument specifies an invalid address.
RETURN VALUE
Select returns the number of descriptors contained in the
Printed 4/6/89 1
SELECT(2) COMMAND REFERENCE SELECT(2)
bit masks, or -1 if an error occurred. If the time limit
expires then select returns 0.
CAVEATS
The descriptor masks (up to "(nfd+31)/32") are always
modified on return, even if the call returns as the result
of the timeout.
The return value of mask for descriptors greater than
specified by nfd is undefined. In other words, the bits
specified by:
mask[f/32] & (1 << (f % 32))
where f is greater than or equal to nfd should not be
assumed to have any meaningful value.
The magic constant 32 mentioned above is the number of bits
in a long.
SEE ALSO
accept(2), connect(2), read(2), recv(2), send(2), and
write(2).
Printed 4/6/89 2
%%index%%
na:288,89;
sy:377,1764;
de:2141,1507;
di:3648,611;
rv:4259,246;4865,160;
ca:5025,679;
se:5704,254;
%%index%%000000000132