|
|
#include <sys/time.h> #include <sys/types.h> #include <sys/select.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);
The descriptor sets are stored as bit fields in arrays of integers. The following macros are provided for manipulating such descriptor sets:
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. In UnixWare 7 and previous releases of UnixWare, its value was 1024. FD_SETSIZE was increased to 4096 in UnixWare 7 Release 7.0.1. See ``Notices''.
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 affect 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.
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 descriptor sets are always modified on return, even if the call returns as the result of a timeout.
A file descriptor for a socket that is listening for connections will, when connections are available, indicate that it is ready for reading. A file descriptor for a socket that is connecting asynchronously will, when a connection has been established, indicate that it is ready for writing.
A connection failure on a file descriptor for a socket
sets exceptfds
for the file descriptor.
When a socket is shut down or closed for read operations,
the setting of bits in exceptfds
is
determined by the value of the ss_selectrdband
parameter set by
inconfig(1Mtcp).