select()
Provides synchronous socket I/O multiplexing.
Syntax
result = select(count, reads, writes, exceptions, timeout)
int | result, | count; |
fd_set | *reads, | *writes, *exceptions; |
struct timeval *timeout; |
Parameters
result | Returns the number of socket descriptors contained in the |
| select() call bitmasks. |
| |
| 0 means the time limit has expired and all the bitmasks are |
| cleared. |
count | Specifies the number of sockets for select() to examine. |
| Select() examines socket descriptors from 0 to |
| Currently, users are allowed a maximum of 31 socket |
| descriptors, so the valid range for count is 1 to 31. Since socket |
| descriptors are numbered starting with 0, callers should specify |
| count as their highest socket descriptor + 1. (Note: count |
| specifies the number of socket descriptors for selection. Hence, |
| a count of 5 means that the select() call will examine socket |
| descriptors from 0 through 4.) |
reads | Pointer to a bitmask to specify which socket descriptors (from 0 |
| to |
| FD_ZERO if no descriptors need to be selected for reads. |
| On return, it contains a pointer to the bitmask specifying which |
| socket descriptors (from 0 to |
| Use the FD_SET macro and fd_set variable type to set the |
| socket descriptors for reads before you issue the select() |
| call. After issuing select(), use FD_ISSET to test for the |
| bits in the bitmask. Refer to •Socket Descriptor Utilities" for |
| more information on clearing, setting, and testing the bits in the |
| bitmasks. |
writes | Pointer to a bitmask to specify which socket descriptors (from 0 |
| to |
| FD_ZERO if no descriptors need to be selected for writes. |
| On return, it contains a pointer to the bitmask specifying which |
| socket descriptors (from 0 to |
| Use the FD_SET macro and fd_set variable type to set the |
| socket descriptors for writes before you issue the select() |
| call. After issuing select(), use FD_ISSET to test for the |
| bits in the bitmask. Refer to •Socket Descriptor Utilities" for |
| more information on clearing, setting, and testing the bits in the |
| bitmasks. |
412 Berkeley Software Distribution Interprocess Communication