event_base_new
2016-09-22 16:54:45 6 举报
AI智能生成
`event_base_new`是一个用于创建事件基础对象的函数,它在libevent库中被广泛使用。事件基础对象是libevent库的核心组件,它提供了一种高效的方式来处理并发事件,如网络连接、定时器等。通过调用`event_base_new`函数,我们可以创建一个事件基础对象,然后使用该对象来注册、触发和处理各种事件。这个函数通常在主程序的初始化阶段被调用,以确保所有需要的事件都能正确地被管理。
作者其他创作
大纲/内容
event_base_new
event_config_new
struct event_configq { struct event_config_entry *tqh_first; struct event_config_entry **tqh_last;}entries;
int n_cpus_hint;
enum event_method_feature require_features;
enum event_base_config_flag flags;
EVENT_BASE_FLAG_NOLOCK=0x01
EVENT_BASE_FLAG_IGNORE_ENV=0x02
EVENT_BASE_FLAG_STARTUP_IOCP=0x04
EVENT_BASE_FLAG_NO_CACHE_TIME=0x08
EVENT_BASE_FLAG_EPOLL_USE_CHANGELIST=0x10
TAILQ_INIT(&cfg->entries)
初始化队列
event_base_new_with_config
min_heap_ctor(&base->timeheap);
初始化timeheap
TAILQ_INIT(&base->eventqueue);
初始化base->defer_queue
defer_queue.notify_fn = notify_base_cbq_callback;
defer_queue.notify_arg = base;
初始化base->io
#define event_io_map event_signal_map
io->nentries=0
io->entries=NULL
初始化base->sigmap
sig->nentries = 0
sig->entries = NULL
初始化base->changelist
cl->changes = NULL;
cl->changes_size = 0;
cl->n_changes = 0;
for选择事件触发器
base->evsel = eventops[i]
evports
Solaris 10
kqueue
Windows
epoll
Linux
...
base->evbase = base->evsel->init(base);
epoll_init
epfd = epoll_create(32000)
make_socket_closeonexec(epfd)
epollop->epfd = epfd
epollop->nevents = INITIAL_NEVENT
evsig_init(base);
make_socket_closeonexec(base->sig.ev_signal_pair[0|1])
make_socket_nonblocking(base->sig.ev_signal_pair[0|1])
ev->ev_base = base;
ev->ev_callback = evsig_cb;
ev->ev_arg = base;
ev->ev_fd = base->sig.ev_signal_pair[1];
ev->ev_events = EV_READ | EV_PERSIST
ev->ev_res = 0;
ev->ev_flags = EVLIST_INIT(0x80);
ev->ev_ncalls = 0;
ev->ev_pncalls = NULL;
base->evsigsel = &evsigops;
evsig_add
evsig_del
0 条评论
回复 删除
下一页