1 poll operation of Linux
The poll operation of Linux files has two main purposes: first, to see if there are read and write events on the file, and second, to provide the interface of Operation Waitqueue to the upper interface such as Epoll, For example, Epoll can register its own callback into the waitqueue of the file by invoking the poll operation of the file it is monitoring directly, so called callback is the function in Waitqueue entry, so that when the file that Epoll is watching has data coming, The callback that is registered to Waitqueue is called back, and the file can be placed in the Epoll rdllist.
2 Ep_item_poll and Ep_poll_callback
Ep_item_poll registers Ep_poll_callback as the function of Waitqueue entry to the waitqueue of the monitored files.
3 Rdllist and Ovflist
Files that have read and write events are placed in the rdllist queue. When the user epoll_wait, the need to copy the rdllist to the user space and lock, this time if a new event, the first place in the Ovflist, in the rdllist is not busy when put into it.
4 Epoll_create, Epoll_ctl and epoll_wait
Epoll_create is to create a epoll entity for the current thread to monitor the files that need to be monitored, epoll_ctl to add the files that need to be monitored to epoll, epoll_wait to see if there is an event coming, and to do the appropriate processing because it is always monitored, so A dead loop is needed to keep epoll_wait.
The implementation principle of Linux Epoll