SELECT(2) SELECT(2) NAME select - synchronous I/O multiplexing SYNOPSIS #include #include 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; DESCRIPTION _S_e_l_e_c_t examines the I/O descriptor sets whose addresses are passed in _r_e_a_d_f_d_s, _w_r_i_t_e_f_d_s, and _e_x_c_e_p_t_f_d_s to see if some of their descriptors are ready for reading, are ready for writing, or have an exceptional condition pending, respectively. The first _n_f_d_s descriptors are checked in each set; i.e. the descriptors from 0 through _n_f_d_s-1 in the descriptor sets are examined. On return, _s_e_l_e_c_t replaces the given descriptor sets with subsets consisting of those descriptors that are ready for the requested operation. The total number of ready descrip‐ tors in all the sets is returned in _n_f_o_u_n_d. The descriptor sets are stored as bit fields in arrays of integers. The following macros are provided for manipulating such descriptor sets: _F_D__Z_E_R_O_(_&_f_d_s_e_t_) initializes a descriptor set _f_d_s_e_t to the null set. _F_D__S_E_T_(_f_d_, _&_f_d_s_e_t_) includes a particular descriptor _f_d in _f_d_s_e_t. _F_D__C_L_R_(_f_d_, _&_f_d_s_e_t_) removes _f_d from _f_d_s_e_t. _F_D__I_S_S_E_T_(_f_d_, _&_f_d_s_e_t_) is nonzero if _f_d is a member of _f_d_s_e_t, zero otherwise. The behavior of these macros is undefined if a descriptor value is less than zero or greater than or equal to _F_D__S_E_T_S_I_Z_E, which is normally at least equal to the maximum number of descriptors supported by the system. If _t_i_m_e_o_u_t is a non-zero pointer, it specifies a maximum interval to wait for the selection to complete. If _t_i_m_e_o_u_t is a zero pointer, the select blocks indefinitely. To affect a poll, the _t_i_m_e_o_u_t argument should be non-zero, pointing to a zero-valued timeval structure. Any of _r_e_a_d_f_d_s, _w_r_i_t_e_f_d_s, and _e_x_c_e_p_t_f_d_s may be given as zero pointers if no descriptors are of interest. RETURN VALUE _S_e_l_e_c_t returns the number of ready descriptors that are contained in the descriptor sets, or -1 if an error occurred. If the time limit expires then _s_e_l_e_c_t returns 0. If _s_e_l_e_c_t returns with an error, including one due to an interrupted call, the descriptor sets will be unmodified. ERRORS An error return from _s_e_l_e_c_t indicates: [EBADF] One of the descriptor sets specified an invalid descrip‐ tor. [EINTR] A signal was delivered before the time limit expired and before any of the selected events occurred. [EINVAL] The specified time limit is invalid. One of its compo‐ nents is negative or too large. SEE ALSO accept(2), connect(2), read(2), write(2), recv(2), send(2), getdtable‐ size(2) BUGS Although the provision of _g_e_t_d_t_a_b_l_e_s_i_z_e(2) was intended to allow user programs to be written independent of the kernel limit on the number of open files, the dimension of a sufficiently large bit field for select remains a problem. The default size FD_SETSIZE (currently 256) is somewhat larger than the current kernel limit to the number of open files. However, in order to accommodate programs which might poten‐ tially 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 . _S_e_l_e_c_t 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 _s_e_l_e_c_t call. 4.2 Berkeley Distribution May 15, 1986 SELECT(2)