Your program uses the
select( ) system call to determine when sockets
are ready for writing, have data waiting to be read, or have an
exceptional condition (e.g., out-of-band data has arrived). Using
select( ) requires the use of the
fd_set data type, which typically entails the use
family of macros. In most
FD_SET( ) and
), in particular, are susceptible to an array overrun.
Do not use the
FD_*( ) family of macros. Instead,
use the macros that are provided in this recipe. The
FD_CLR( ) macros will modify an
fd_set object without performing any bounds
checking. The macros we provide will do proper bounds checking.
call is normally used to multiplex sockets. In a single-threaded
select( ) allows you to build sets of
socket descriptors for which you wish to wait for data to become
available or that you wish to have available to write data to. The
data type is used to hold a list of the
socket descriptors, and several standard macros are used to
manipulate objects of this type.
fd_set is defined as a structure with a
single member that is a statically allocated array of long integers.
Because socket descriptors are always numbered starting with 0 and
ending with the highest allowable descriptor, the array of integers
fd_set is actually treated as a bitmask with a one-to-one correspondence ...