All rights reserved.
Redistribution and use in source and binary forms are permitted
provided that the above copyright notice and this paragraph are
duplicated in all such forms and that any documentation,
advertising materials, and other materials related to such
distribution and use acknowledge that the software was developed
by the University of California, Berkeley. The name of the
University may not be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
@(#)select.2 6.6 (Berkeley) 02/14/89
#include <sys/types.h> #include <sys/time.h>nfound = select(nfds, readfds, writefds, exceptfds, timeout) int nfound, nfds; fd_set *readfds, *writefds, *exceptfds; struct timeval *timeout;
FD_SET(fd, &fdset) FD_CLR(fd, &fdset) FD_ISSET(fd, &fdset) FD_ZERO(&fdset) int fd; 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: "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 , which is normally at least equal to the maximum number of descriptors supported by the system.
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 affect a poll, the timeout argument should be non-zero, pointing to a zero-valued timeval structure.
Any of readfds , writefds , and exceptfds may be given as zero pointers if no descriptors are of interest.
15 [EBADF] One of the descriptor sets specified an invalid descriptor.
15 [EINTR] A signal was delivered before the time limit expired and before any of the selected events occurred.
15 [EINVAL] The specified time limit is invalid. One of its components is negative or too large.
Select should probably return the time remaining from the original timeout, if any, by modifying the time value in place. This may be implemented in future versions of the system. Thus, it is unwise to assume that the timeout value will be unmodified by the select call.