Epol Study Notes to learn more about epoll
Epol Study Notes
LEpollRelated system calls
Epoll_create ()
Epoll_ctl ()
Epoll_wait ()
LInt epoll_create (int size );
Create an epoll handle.
LInt epoll_ctl (int epfd, int op, int fd, struct epoll_event * event );
Epoll event registration function.
1. The first parameter is the returned value of epoll_create.
2. The second parameter represents an action, represented by three macros:
EPOLL_CTL_ADD: Register a new fd to epfd;
EPOLL_CTL_MOD: Modify the listening events of the registered fd;
EPOLL_CTL_DEL: Delete an fd from epfd.
3. The third parameter is the fd to be monitored.
4. The fourth parameter is to tell the kernel what to listen.
The structure of struct epoll_event is as follows:
Typedef union epoll_data
{// Save the data related to a file descriptor of the trigger event
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 can be a collection of the following macros:
LInt epoll_wait (int epfd, struct epoll_event * events, int maxevents, int timeout );
Collect events that have occurred in epoll monitoring events.
LEdge TriggeredWorking Mode
@ Based on non-blocking file handle
@ It must be suspended only when read () or write () returns EAGAIN.
However, this does not mean that every read () operation needs to be performed cyclically until an EAGAIN is generated. When read () when the returned data length is less than the requested data length, you can determine that there is no data in the buffer at this time, so that the read event has been processed.