Multiplexing IO --- epoll

A, epoll_create function

  Function declaration: int epoll_create (int size)
  This function generates a dedicated file descriptor epoll. It is in fact a core application space used to store whether you want to focus on the occurrence of socket fd as well as what events happened. size is the maximum number of socket fd you can follow on the epoll fd.

Two, epoll_ctl function   

    Function declaration: int epoll_ctl (int epfd, int op, int fd, struct epoll_event * event)
      function: an event on a file descriptor control, you can register events, modify events, delete events.
      the epfd: epoll_create epoll generated by the dedicated file descriptors;
      OP: the operation to be performed, EPOLL_CTL_ADD registration, EPOLL_CTL_MOD modify, EPOLL_CTL_DEL deleted;
      FD: file descriptor associated;
      Event: the pointer epoll_event;  
      Success: 0; Failure: -1
three, epoll_wait function   
    function declaration: int epoll_wait (int epfd, struct epoll_event * events, int maxevents, int timeout)
    function: this function is used to poll occurring I / O events;
      the epfd: the epoll dedicated generated by the epoll_create file descriptors;
      epoll_event: An array of processing events return passage;
      maxevents: number of events that can be processed per;
      timeout: timeout value to wait for I / O event;
      success: returns the number of events; failed: -1

四、struct epoll_event

  Structure epoll_event are registered for the event of interest and events that occurred return to be processed.

of Union epoll_data {typedef 
   void * ptr; 
   int fd; 
   __uint32_t U32; 
   __uint64_t u64; 
} epoll_data_t; // save a file descriptor trigger event related data 

struct {epoll_event 
   __uint32_t Events; / * Event * epoll / 
   epoll_data_t the Data; / the User Data variable * * / 
}; 

  Represents an event where the events of interest and the event is triggered, the possible values ​​are:

    Epoll EPOLLET ET operating mode of
    EPOLLHUP indicates that the corresponding file descriptor is dropped
    EPOLLERR indicates that the corresponding file descriptor error occurs
    EPOLLPRI indicates that the corresponding file descriptor number of emergency-readable
    EPOLLOUT indicates that the corresponding file descriptor can be written
    EPOLLIN designate corresponding the file descriptor can be read

Guess you like

Origin www.cnblogs.com/jiangyu0331/p/12009732.html