Allows you to poll or check a group of sockets for I/O activity. This function indicates which sockets are ready to be read or written, or which sockets have an exception pending. Format #include <time.h> int select ( int nfds, int *readfds, int *writefds, int *execptfds, struct timeval *timeout ); (_DECC_V4_SOURCE) int select ( int nfds, fd_set *readfds, fd_set *writefds, int *execptfds, struct timeval *timeout ); (not_DECC_V4_SOURCE)
1 – Arguments
nfds The number of open objects that may be ready for reading or writing or that have exceptions pending. The nfds argument is normally limited to FD_SETSIZE, which is defined in the SOCKET.H header file. Note that a single process can have a maximum of 65535 simultaneous channels (including sockets) on OpenVMS Alpha and I64 systems, and a maximum of 2047 on OpenVMS VAX systems. readfds A pointer to an array of bits, organized as integers, that should be examined for read readiness. If bit n of the longword is set, socket descriptor n is checked to see whether it is ready to be read. All bits set in the bit mask must correspond to the file descriptors of sockets. The select() function cannot be used on normal files. On return, the array to which readfds points contains a bit mask of the sockets that are ready for reading. Only bits that were set on entry to the select() function can be set on exit. writefds A pointer to an array of bits, organized as integers, that should be examined for write readiness. If bit n of the longword is set, socket descriptor n is checked to see whether it is ready to be written to. All bits set in the bit mask must correspond to socket descriptors. On return, the array to which writefds points contains a bit mask of the sockets that are ready for writing. Only bits that were set on entry to the select() function are set on exit. exceptfds A pointer to an array of bits, organized as integers, that is examined for exceptions. If bit n of the longword is set, socket descriptor n is checked to see whether it has any pending exceptions. All bits set in the bit mask must correspond to the file descriptors of sockets. On return, the array exceptfds pointer contains a bit mask of the sockets that have exceptions pending. Only bits that were set on entry to the select() function can be set on exit. timeout The length of time that the select() function should examine the sockets before returning. If one of the sockets specified in the readfds, writefds, and exceptfds bit masks is ready for I/O, the select() function returns before the timeout period expires. The timeout argument points to a timeval structure.
2 – Description
This function determines the I/O status of the sockets specified in the various mask arguments. It returns when a socket is ready to be read or written, when the timeout period expires, or when exceptions occur. If timeout is a non-null pointer, it specifies a maximum interval to wait for the selection to complete. If the timeout argument is null, the select() function blocks indefinitely until a selected event occurs. To effect a poll, the value for timeout should be non-null, and should point to a zero-value structure. If a process is blocked on a select() function while waiting for input for a socket and the sending process closes the socket, then the select() function notes this as an event and unblocks the process. The descriptors are always modified on return if the select() function returns because of the timeout. NOTE When the socket option SO_OOBINLINE is set on the device socket, the select() function on both read and exception events returns the socket mask that is set on both the read and the exception mask. Otherwise, only the exception mask is set. Related Functions See also accept(), connect(), read(), recv(), recvfrom(), recvmsg(), send(), sendmsg(), sendto(), and write().
3 – Return Values
n The number of sockets ready for I/O or pending exceptions. This value matches the number of returned bits that are set in all output masks. 0 The select() function timed out before any socket became ready for I/O. -1 Error; errno is set to indicate the error.
4 – Errors
EBADF One or more of the I/O descriptor sets specified an invalid file descriptor. EINTR A signal was delivered before the time limit specified by the timeout argument expired and before any of the selected events occurred. EINVAL The time limit specified by the timeout argument is invalid. The nfds argument is less than zero, or greater than or equal to FD_SETSIZE. EAGAIN Allocation of internal data structures failed. A later call to the select() function may complete successfully. ENETDOWN TCP/IP Services was not started. ENOTSOCK The socket descriptor is invalid.