The <select.h>
header defines the select()
macro, which is used for synchronous I/O multiplexing.
Functions and Macros
select Function
Purpose
Examines the I/O descriptor sets whose addresses are passed in to see if some of their descriptors are ready.
Declared In
posix/sys/select.h
Prototype
int select ( intfd
, fd_set *rfds
, fd_set *wfds
, fd_set *efds
, struct timeval *timeout
)
Parameters
-
→ fd
- The descriptors are checked in each set; that is, the descriptors from zero (0) through
fd
- 1 in the descriptor sets are examined. -
→ rfds
- The descriptors are checked to see if some of them are ready for reading.
-
→ wfds
- The descriptors are checked to see if some of them are ready for writing.
-
→ efds
- The descriptors are checked to see if some of them have an exceptional condition pending.
-
→ timeout
- If
timeout
is a non-NULL
pointer, it specifies a maximum interval to wait for the selection to complete. Iftimeout
is aNULL
pointer, thenselect()
blocks indefinitely. To affect a poll, thetimeout
argument should be non-NULL
, pointing to a zero-valuedtimeval
structure.
Returns
Returns the number of ready descriptors that are contained in the descriptor sets. Otherwise, -1 is returned and the global variable errno
is set to indicate the error. If the time limit expires, select()
returns zero (0). If select()
returns with an error, including one due to an interrupted call, the descriptor sets are unmodified.
Compatibility
This function is not in the C99 specification.
See Also
accept()
, connect()
, read()
, recv()
, send()
, write()