Introduction of Epoll Series functions
#include <sys/epoll.h>
int epoll_create (int size);
int epoll_create1 (int flags);
int epoll_ctl (int epfd, int op, int fd, struct epoll_event *event);
int epoll_wait (int epfd, struct epoll_event *events, int maxevents, int timeout);
* Epoll_create (2) creates a Epoll instance and returns a file descriptor referring to that instance. (The more recent
Epoll_create1 (2) extends the functionality of Epoll_create (2).)
* Interest in particular file descriptors is then registered via EPOLL_CTL (2). The set of file descriptors currently
Registered on a Epoll instance is sometimes called a epoll set.
* EPOLL_WAIT (2) waits for I/O events, blocking the calling thread if no events are currently.
1. Epoll_create1 produces a Epoll instance that returns the handle to the instance. Flag can be set to 0 or epoll_cloexec, the 0 o'clock function behaves the same as Epoll_create, and the EPOLL_CLOEXEC flag is similar to the O_CLOEXEC flag on open, which closes the file descriptor when the process is replaced.
2, Epoll_ctl:
(1) Epfd:epoll instance handle;
(2) OP: The operation of the document descriptor FD, mainly Epoll_ctl_add, Epoll_ctl_del, etc.
(3) FD: The target file descriptor required to operate;
(4) Event: Structural body pointer
typedef Union EPOLL_DATA {
void *ptr;
int FD;
uint32_t u32;
uint64_t U64;
} epoll_data_t;
struct Epoll_event {
uint32_t events; * Epoll Events * *
epoll_data_t data; /* USER Data variable * *
};
Events parameters mainly include Epollin, Epollout, Epollet, epolllt, etc. general data community we set its member FD, that is, the third parameter of the EPOLL_CTL function.
3, Epoll_wait:
(1) Epfd:epoll instance handle;
(2) Events: Structural body pointers
(3) Maxevents: Maximum number of events
(4) Timeout: timeout, set to-1 means never time out