SYNOPSIS
#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);
FD_SET(int fd, fd_set *fdset);
FD_CLR(int fd, fd_set *fdset);
FD_ISSET(int fd, fd_set *fdset);
FD_ZERO(fd_set *fdset);
DESCRIPTION
The
The
The nfds argument specifies the range of file descriptors to
be tested. The
If the readfds argument is not NULL, it points to an object of type fd_set that on input specifies the file descriptors to be checked for being ready to read, and on output indicates which file descriptors are ready to read.
If the writefds argument is not NULL, it points to an object of type fd_set that on input specifies the file descriptors to be checked for being ready to write, and on output indicates which file descriptors are ready to write.
If the exceptfds argument is not NULL, it points to an object of type fd_set that on input specifies the file descriptors to be checked for error conditions pending, and on output indicates which file descriptors have error conditions pending.
On successful completion, the objects pointed to by the readfds, writefds, and exceptfds arguments are modified to indicate which file descriptors are ready for reading, ready for writing, or have an error condition pending, respectively. For each file descriptor less than nfds, the corresponding bit is set on successful completion if it was set on input and the associated condition is true for that file descriptor.
If the timeout argument is not a NULL
pointer, it points to an object of type struct timeval
that specifies a maximum interval to wait for the selection to complete.
If the timeout argument points to an object of type
struct timeval whose members are 0,
The use of a timeout does not affect any pending timers set by
If the readfds, writefds, and
exceptfds arguments are all NULL pointers
and the timeout argument is not NULL,
File descriptors associated with regular files always select true for ready to read, ready to write, and error conditions.
On failure, the objects pointed to by the readfds, writefds, and exceptfds arguments are not modified. If the timeout interval expires without the specified condition being true for any of the specified file descriptors, the objects pointed to by the readfds, writefds, and exceptfds arguments have all bits set to 0.
If a process is blocked on a
File descriptor masks of type fd_set can be initialized
and tested with
- FD_CLR(fd, &fdset)
-
Clears the bit for the file descriptor fd in the file descriptor set fdset.
- FD_ISSET(fd, &fdset)
-
Returns a non-zero value if the bit for the file descriptor fd is set in the file descriptor set pointed to by fdset, and 0 otherwise.
- FD_SET(fd, &fdset)
-
Sets the bit for the file descriptor fd in the file descriptor set fdset.
- FD_ZERO(&fdset)
-
Initializes the file descriptor set fdset to have zero bits for all file descriptors.
Unexpected errors may occur if fd is less than 0 or greater than or equal to FD_SETSIZE in any of these macros.
- Note:
-
The default value of FD_SETSIZE (currently 256) is smaller than the default limit on the number of open files. 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/select.h>.
PARAMETERS
- nfds
-
Specifies how many descriptors should be examined. The descriptors checked are 0 through nfds-1.
- readfds
-
Points to a bit mask that specifies the file descriptors to check for reading.
- writefds
-
Points to a bit mask that specifies the file descriptors to check for writing.
- exceptfds
-
Points to a bit mask that specifies the file descriptors to check for exception conditions.
- timeout
-
When non-NULL, contains the address of a struct timeval that specifies how long to wait for the required condition before returning to the caller. When NULL, forces the call to block until a descriptor becomes ready or until a signal occurs.
RETURN VALUES
If successful,
- EBADF
-
One or more of the file descriptor sets specified a file descriptor that is not a valid open file descriptor or specified a file descriptor that does not support selection.
- EINTR
-
A signal interrupted the call or the time limit expired.
- EISDIR
-
One or more the file descriptor sets specified a file descriptor that refers to an open directory.
- EINVAL
-
A component of timeout is outside the acceptable range.
CONFORMANCE
UNIX98.
MULTITHREAD SAFETY LEVEL
MT-Safe.
PORTING ISSUES
Windows 95 does not correctly return ECONNREFUSED for non-blocking
socket connections; the connection attempt blocks indefinitely. Therefore, on
Windows 95, you should always use a timeout in your calls to
AVAILABILITY
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition
SEE ALSO
PTC MKS Toolkit 10.5 Documentation Build 40.