Linux I/O multi-channel Transfer Model:
In this model, if the requested I/O operation is blocked, it does not actually block I/O, but waits for one of the functions. During this period, i/O can also perform other operations. Select () and Poll () belong to this model.
Select () function description
Header file |
# Include <sys/types. h> # Include <sys/time. h> # Include <unistd. h> |
Prototype |
Int select (INT numfds, fd_set * readfds, fd_set * writefds, fd_set * exeptfds, struct timeval * timeout |
Parameters |
Numfds: file descriptor with the highest number to be checked + 1 Readfds: a set of read file descriptors monitored by select (). Writefds: a set of write file descriptors monitored by select (). Exeptfds: a collection of exception handling file descriptors monitored by select () Timeout: --- NULL: always wait until the signal or file descriptor is captured. --- Specific value: struct timeval pointer. If the timeout time is not ready, return immediately --- 0: Never wait. test all specified descriptors and return immediately |
Return Value |
Success: The file descriptor is ready. -1: Error |
Four macros for file descriptor operations:
Fd_zero (fd_set * Set) |
Clears a file descriptor set. |
Fd_set (int fd, fd_set * Set) |
Add a file descriptor to the file descriptor set |
Fd_clr (int fd, fd_set * Set) |
Delete a file descriptor from the collection |
Fd_isset (int fd, fd_set * Set) |
Test whether a given location in the SET has changed |