IO multiplexing Select epool programming 20210222

select model

The system provides the select function to implement the multiplexed input/output model.
The select system call is used to allow our program to monitor the status changes of multiple file handles. The program will stop at select and wait until one or more of the monitored file handles have changed their status. Regarding the file handle, it is actually an integer. The handles we are most familiar with are 0, 1, and 2. 0 is standard input, 1 is standard output, and 2 is standard error output. 0, 1, 2 are represented by integers, and the corresponding FILE * structure is represented by stdin, stdout, and stderr.

int select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,struct timeval *timeout);
struct timeval  
{
    
      
    time_t tv_sec;//second  
    time_t tv_usec;//minisecond  
}; 
  • maxfdp: The total number of file descriptors being monitored, which is 1 larger than the maximum value of file descriptors in all file descriptor sets, because file descriptors are counted from 0;
  • readfds, writefds, exceptset: point to the set of descriptors corresponding to events such as readable, writable, and exception, respectively.
  • timeout: Used to set the timeout period of the select function, that is, tell the kernel how long to wait before giving up waiting. timeout == NULL, which means to wait for infinite time

Guess you like

Origin blog.csdn.net/Narutolxy/article/details/113945120