在libevent中使用EVLOOP_NONBLOCK
Using EVLOOP_NONBLOCK in libevent
在libevent
中,我添加了以下代码:
while (run) {
event_base_loop(base, EVLOOP_NONBLOCK | EVLOOP_ONCE);
}
如果我将其与以下内容进行比较:
event_base_dispatch(base);
这两个语句相等吗?
不,event_base_dispatch(base)
调用相当于event_base_loop(base, 0)
,这意味着它既不会在第一批事件之后停止(像event_base_loop
与EVLOOP_ONCE
一样),也不会在没有事件准备时立即返回(像event_base_loop
与EVLOOP_NONBLOCK
一样)。
你可能想读一下Nick Mathewson写的关于libevent的书:http://www.wangafu.net/~nickm/libevent-book/Ref3_eventloop.html