这篇文件讲解下上面的几篇文章中欠下的几个函数解释。在看这个之前,请移步这篇文章这里说明了libevent库在编译的时候已经决定了所使用的I/O复用机制,系统中提供了五种机制:在这里指选择一种来说明 epoll
在even-internal.h文件中有一个结构体,
38 struct eventop {
39 const char *name;
40 void *(*init)(struct event_base *);
41 int (*add)(void *, struct event *);
42 int (*del)(void *, struct event *);
43 int (*dispatch)(struct event_base *, void *, struct timeval *);
44 void (*dealloc)(struct event_base *, void *);
45 /* set if we need to reinitialize the event base */
46 int need_reinit;
47 };
这个结构体中的每个字段,都是函数指针,函数指针其实就是C语言中的多态,上面的这五个字段在编译的时候指向某个系统调用中的五个函数。也就是event_base中的evsel指针。在epoll机制中,首先封装了struct event :
59 struct evepoll {
60 struct event *evread;
61