The implementation principle of Linux Epoll

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.