epoll源码探秘(epoll_create)
epoll系列的系统函数,很简单,但是很强大。epoll_create(),epoll_ctl() , epoll_wait(),三个就够了。
一些重要的结构:
/*
* Each file descriptor added to the eventpoll interface will
* have an entry of this type linked to the "rbr" RB tree.
* Avoid increasing the size of this struct, there can be many thousands
* of these on a server and we do not want this to take another cache line.(红黑树单节点)
*/
struct epitem {
union {
/* RB tree node links this structure to the eventpoll RB tree */
struct rb_node rbn;
/* Used to free the struct epitem */
struct rcu_head rcu;
};
/* List header used to link this structure to the eventpoll ready list (列表头用于连接结构的eventpoll就绪列表)*/
struct list_head rdllink;
/*
* Works together "struct eventpoll"->ovflist in keeping the
* single linked chain of items.
*/
struct epitem *next;
/* The file descriptor information this item refers to (关联的文件描述符)*/
struct epoll_filefd ffd;
/* Number of active wait queue attached to poll operations (轮询操作)*/
int nwait;
/* List containing poll wait queues */
struct list_head pwqlist;
/* The "container" of this item */
struct eventpoll *ep;
/* List header used to link this item to the "struct file" items list */
struct list_head fllink;