hostapd eloop初始化
\hostapd-2.10\src\utils\eloop.c
struct eloop_data {
int max_sock;
size_t count; /* sum of all table counts */
#ifdef CONFIG_ELOOP_POLL
size_t max_pollfd_map; /* number of pollfds_map currently allocated */
size_t max_poll_fds; /* number of pollfds currently allocated */
struct pollfd *pollfds;
struct pollfd **pollfds_map;
#endif /* CONFIG_ELOOP_POLL */
#if defined(CONFIG_ELOOP_EPOLL) || defined(CONFIG_ELOOP_KQUEUE)
int max_fd;
struct eloop_sock *fd_table;
#endif /* CONFIG_ELOOP_EPOLL || CONFIG_ELOOP_KQUEUE */
#ifdef CONFIG_ELOOP_EPOLL
int epollfd;
size_t epoll_max_event_num;
struct epoll_event *epoll_events;
#endif /* CONFIG_ELOOP_EPOLL */
#ifdef CONFIG_ELOOP_KQUEUE
int kqueuefd;
size_t kqueue_nevents;
struct kevent *kqueue_events;
#endif /* CONFIG_ELOOP_KQUEUE */
struct eloop_sock_table readers;
struct eloop_sock_table writers;
struct eloop_sock_table exceptions;
struct dl_list timeout;
size_t signal_count;
struct eloop_signal *signals;
int signaled;
int pending_terminate;
int terminate;
};
static struct eloop_data eloop; //eloop.c中定义静态变量eloop
1.仍然从main()函数出发
main()函数中调用hostapd_global_init()函数,从起hostapd命令来看,hostapd -i vap0 -Dnl80211 -c conf,没有-e参数,故entropy_file为NULL
(1)hostapd_global_init()函数
(2)eloop_ini()都干了啥,这里仍然选择梳理epoll
- 静态全局变量eloop 清0
- 创建epoll的句柄
2.main()函数结尾处 调用hostapd_global_run()
(1)hostapd_global_run()函数
(2)eloop_run()
num_poll_fds:需要监听的描述符数目
timeout_ms:愿意等待多长时间。timeout==-1,永远等待;timeout==0,不等待;timeout>0,等待timeout毫秒
进入while循环
得到需要监听的描述符总数,启动poll()函数开始监听
等待事件产生
处理各事件
while结束,eloop_run()函数结束
2.1 eloop_sock_table_set_fds()函数梳理
此处以readers为例梳理,writers exceptions相同
2.2 eloop_sock_table_dispatch_table()函数梳理
仍以readers为例,对比前面netlink初始化代码,能知道handler就是netlink_receive(),当然eloop初始化这会netlink还没有注册,后面注册之后就可以监听了。
总结:
main函数中调用关系
--hostapd_global_init() 初始化eloop
-- hostapd_interface_init()
--hostapd_driver_init()初始化netlink,并注册sock到eloop
--hostapd_setup_interface()
--hostapd_global_ctrl_iface_init()
--hostapd_global_run()