1. I/O model
An input operation typically consists of two different stages: waiting for data to be ready, copying data from the kernel to the process.
Blocking I/O models
Non-blocking I/O model
I/O multiplexing model: The kernel discovery process specifies that one or more I/O conditions are in place, and it notifies the process, supported by select and poll two functions
Signal-driven I/O model: The kernel sends a SIGIO signal notification process when the description word is ready
asynchronous I/O model: Let the kernel initiate an action and notify the process after the entire operation is complete
2. Select function
#include <sys/select.h>
#include <sys/time.h>
int select (int maxfdp1, fd_set *readset, Fd_set *writeset, fd_set *expectset, const struct Timeval *timeout)
The Select function specifies a series of descriptors that return after a descriptive word is ready or waiting for a specified time, returning all the number of descriptive words that are ready
Parameter timeout Specifies the maximum wait time, which is null when the function waits until there is a descriptive child ready
The parameters Readset, Writeset, and Expectset Specify the read, write, and exception condition descriptors for the kernel test. The type of these three parameters describes the word set fd_set, which can be
Use the following 4 macros:
void Fd_zero (Fd_set *fdset)
void fd_set (int fd,fd_set *fdset)
void fd_clr (int FD, fd_set *fdset)
int fd_isset (int FD, fd_set *fdset)//Determine if the FD descriptor in the Fdset descriptor set is ready
The Select function modifies the set of descriptors pointed to by Readset, Writeset, and Expectset, and the three parameters are value-result arguments, and when the function is called, the descriptive word of interest is specified,
When returned, indicates the ready description Word. Therefore, when you recall the Select function, you must reset the descriptor set
The value of MAXFDP1 is the maximum description Word plus 1
I/O multiplexing