INtime SDK Help
select (legacy networking)
INtime Help

The select() function checks the sockets specified in the sets of descriptors supplied as parameters to see if any of the sockets are ready for receiving or sending, or have out of band data pending. On return, the descriptor sets are replaced with subsets consisting of those sockets of each set that are ready for the associated operation.

Only one thread may select on a particular aspect of a socket at a time. For example, one thread may select on only receiving and another thread may simultaneously select on only sending on the same socket, but both threads may not select on receiving on the same socket at the same time. If this is attempted, only one thread will succeed and an EALREADY error will be returned to any other threads.

int select(
    int nfds;
    fd_set * recvfds,
    fd_set * sendfds,
    fd_set * oobfds,
    unsigned short timeout
);

Parameters

nfds
The value of the largest-valued descriptor in all the masks, plus one. In other words, if there are two descriptors with values one and seven, nfds should be eight, not two. The value of nfds may be used as an alternative to FD_SETSIZE.
recvfds
A pointer to a set of socket descriptors to be checked to see if any of them are ready for receiving. On return, it contains a set of ready socket descriptors. A null value causes select() to skip the descriptor set.
sendfds
A pointer to a set of socket descriptors to be checked to see if any of them are ready for sending. On return, it contains a set of ready socket descriptors. A null value causes select() to skip the descriptor set.
oobfds
A pointer to a set of socket descriptors to be checked to see if any of them have out-of-band data pending. On return, it contains a set of ready socket descriptors. A null value causes select() to skip the descriptor set.
timeout
The timeout period in 10-ms units. Setting timeout to 0xffff causes select() to wait until one or more of the sockets specified by the descriptor sets are ready. Setting timeout to 0 causes select() to return immediately with the current status of the sockets specified by the descriptor sets. Setting timeout to any value in between specifies the maximum amount of time to wait for any socket specified by the descriptor sets to become ready.

Remarks

A set of macros is supplied to ease manipulation of sets of socket descriptors.

FD_SET(s, &fds) Adds socket s to descriptor set fds.
FD_CLR(s, &fds) Removes socket s from descriptor set fds.
FD_ISSET(s, &fds) Returns nonzero if socket s is in set fds; if not, returns 0 (zero).
FD_ZERO(&fds) Clears descriptor set fds.

An additional macro is supplied for compatibility with other implementations to convert a timeout specified as a number of seconds and microseconds in a timeval structure to the equivalent number of 10ms ticks required by the select() function. A null pointer translates to a timeout value that causes select() to wait indefinitely. A timeval structure that specifies a timeout of more than 655.35 seconds produces an undefined result.

TV_TICKS(&tv) Converts timeout in timeval structure tv to 10 ms ticks.

Return Values

The total number of ready sockets contained in the descriptor sets, or -1 if an error occurs. If the timeout expires before any sockets become ready, 0 is returned. If select() returns an error, the socket descriptor sets are unmodified.

The select call may be used to determine when more data arrives.

Possible errno values returned on failure are as follows:

EALREADY Another thread is currently performing a select() on at least one of the sockets referenced by recvfds, sendfds or oobfds.
EBADF At least one of the sockets referenced by recvfds, sendfds or oobfds is an invalid descriptor.
EINVAL Invalid nfds parameter specified; the recvfds, sendfds and oobfds pointer parameters are all null.
ENOTSOCK At least one of the descriptors referenced by recvfds, sendfds or oobfds is not a socket.
EUNATCH The TCP/IP kernel has not been loaded.

Requirements

Versions Defined in Include Link to
INtime 3.0 intime/rt/include/sys/socket.h sys/types.h
sys/socket.h
netiff3m.lib
See Also