
SELECT(2)                  UNIX Programmer's Manual                  SELECT(2)

NNAAMMEE
     sseelleecctt - synchronous I/O multiplexing

SSYYNNOOPPSSIISS
     ##iinncclluuddee <<uunniissttdd..hh>>
     ##iinncclluuddee <<ssyyss//ttyyppeess..hh>>
     ##iinncclluuddee <<ssyyss//ttiimmee..hh>>

     _i_n_t
     sseelleecctt(_i_n_t _n_f_d_s, _f_d___s_e_t _*_r_e_a_d_f_d_s, _f_d___s_e_t _*_w_r_i_t_e_f_d_s, _f_d___s_e_t _*_e_x_c_e_p_t_f_d_s,
             _s_t_r_u_c_t _t_i_m_e_v_a_l _*_t_i_m_e_o_u_t)

     FFDD__SSEETT(_f_d, _&_f_d_s_e_t)

     FFDD__CCLLRR(_f_d, _&_f_d_s_e_t)

     FFDD__IISSSSEETT(_f_d, _&_f_d_s_e_t)

     FFDD__ZZEERROO(_&_f_d_s_e_t)

DDEESSCCRRIIPPTTIIOONN
     SSeelleecct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 condi-
     tion 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seelleecctt() replaces the given descriptor
     sets with subsets consisting of those descriptors that are ready for the
     requested operation.  SSeelleecctt() returns the total number of ready descrip-
     tors in all the sets.

     The descriptor sets are stored as bit fields in arrays of integers.  The
     following macros are provided for manipulating such descriptor sets:
     FFDD__ZZEERROO(_&_f_d_s_e_t_x) initializes a descriptor set _f_d_s_e_t to the null set.
     FFDD__SSEETT(_f_d, _&_f_d_s_e_t) includes a particular descriptor _f_d in _f_d_s_e_t.
     FFDD__CCLLRR(_f_d, _&_f_d_s_e_t) removes _f_d from _f_d_s_e_t. FFDD__IISSSSEETT(_f_d, _&_f_d_s_e_t) is non-
     zero 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 FD_SETSIZE, which is normally at least equal to the max-
     imum number of descriptors supported by the system.

     If _t_i_m_e_o_u_t is a non-nil pointer, it specifies a maximum interval to wait
     for the selection to complete.  If _t_i_m_e_o_u_t is a nil pointer, the select
     blocks indefinitely.  To affect a poll, the _t_i_m_e_o_u_t argument should be
     non-nil, 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 nil pointers if
     no descriptors are of interest.

RREETTUURRNN VVAALLUUEESS
     SSeelleecctt() returns the number of ready descriptors that are contained in
     the descriptor sets, or -1 if an error occurred.  If the time limit ex-
     pires, sseelleecctt() returns 0.  If sseelleecctt() returns with an error, including
     one due to an interrupted call, the descriptor sets will be unmodified.

EERRRROORRSS
     An error return from sseelleecctt() indicates:

     [EBADF]       One of the descriptor sets specified an invalid descriptor.

     [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 components
                   is negative or too large.

SSEEEE AALLSSOO
     accept(2),  connect(2),  read(2),  write(2),  recv(2),  send(2),  getdta-
     blesize(2)

BBUUGGSS
     Although the provision of getdtablesize(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 some-
     what larger than the current kernel limit to the number of open files.
     However, in order to accommodate programs which might potentially 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 be-
     fore the inclusion of <_s_y_s_/_t_y_p_e_s_._h>.

     SSeelleecctt() should probably return the time remaining from the original
     timeout, if any, by modifying the time value in place.  This may be im-
     plemented in future versions of the system.  Thus, it is unwise to assume
     that the timeout value will be unmodified by the sseelleecctt() call.

HHIISSTTOORRYY
     The sseelleecctt function call appeared in 4.2BSD.

4.2 Berkeley Distribution       March 10, 1991                               2






































