Select (Unix)


is a system call and application programming interface in Unix-like and POSIX-compliant operating systems for examining the status of file descriptors of open input/output channels. An enhanced facility with support for signal masking is. The select system call is similar to the newer facility introduced in UNIX System V and later operating systems. However, with the C10k problem, both select and poll have been superseded by the likes of, /dev/poll, and I/O completion ports.
One common use of select outside of its stated use of waiting on filehandles is to implement a portable sub-second sleep. This can be achieved by passing NULL for all three fd_set arguments, and the duration of the desired sleep as the timeout argument.
In the C programming language, the select system call is declared in the header file sys/select.h or unistd.h, and has the following syntax:

int select;

ArgumentDescription
This is an integer one more than the maximum of any file descriptor in any of the sets. In other words, while adding file descriptors to each of the sets, you must calculate the maximum integer value of all of them, then increment this value by one, and then pass this as nfds.
type holding the file descriptors to be checked for being ready to read, and on output indicates which file descriptors are ready to read. Can be.
type holding the file descriptors to be checked for being ready to write, and on output indicates which file descriptors are ready to write. Can be.
type holding the file descriptors to be checked for exceptional conditions pending, and on output indicates which file descriptors have exceptional conditions pending. An example of an exceptional condition is presence of out-of-band data on a TCP socket. Can be.
Structure of type struct timeval that specifies a maximum interval to wait for the selection to complete. If the timeout argument points to an object of type struct timeval whose members are 0, does not block. If the timeout argument is, select blocks until an event causes one of the masks to be returned with a valid value. Linux will update the timeout in place to indicate how much time was elapsed, though this behavior is not shared by most other Unix systems.

fd_set type arguments may be manipulated with four utility macros:, and.
Select returns the total number of bits set in and, or zero if the timeout expired, and -1 on error.
The sets of file descriptor used in select are finite in size, depending on the operating system. The newer system call provides a more flexible solution.

Example


  1. include
  2. include
  3. include
  4. include
  5. include
  6. include
  7. include
  8. include
  9. include
  10. include
  11. include
  12. include
  13. define PORT "9421"
void die
typedef struct addrinfo AddressInfo;
int main