event_base_new
2016-09-22 16:54:45 6 举报
AI智能生成
`event_base_new`是一个用于创建事件基础对象的函数,它在libevent库中被广泛使用。事件基础对象是libevent库的核心组件,它提供了一种高效的方式来处理并发事件,如网络连接、定时器等。通过调用`event_base_new`函数,我们可以创建一个事件基础对象,然后使用该对象来注册、触发和处理各种事件。这个函数通常在主程序的初始化阶段被调用,以确保所有需要的事件都能正确地被管理。
作者其他创作
大纲/内容
event_config_new
cfg = calloc(1, sizeof(struct event_config))
TAILQ_HEAD(event_configq, event_config_entry) entries;
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
base = calloc(1, sizeof(struct event_base)
gettime(base, &base->event_tv)
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=calloc(1, sizeof(struct epollop))
epollop->epfd = epfd
epollop->events = mm_calloc(INITIAL_NEVENT(32), sizeof(struct epoll_event))
epollop->nevents = INITIAL_NEVENT
evsig_init(base);
evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, base->sig.ev_signal_pair)
make_socket_closeonexec(base->sig.ev_signal_pair[0|1])
make_socket_nonblocking(base->sig.ev_signal_pair[0|1])
event_assign(&base->sig.ev_signal, base, base->sig.ev_signal_pair[1],EV_READ | EV_PERSIST, evsig_cb, base);
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
event_base_priority_init(base, 1)
0 条评论
下一页