name5566
name5566

Reputation: 91

Using EVLOOP_NONBLOCK in libevent

In libevent I've added the following code:

while (run) {
  event_base_loop(base, EVLOOP_NONBLOCK | EVLOOP_ONCE);
}

If I compare this to the following:

event_base_dispatch(base);

Are these two statements equal?

Upvotes: 0

Views: 3463

Answers (1)

Remi Gacogne
Remi Gacogne

Reputation: 4853

No, the event_base_dispatch(base) call is equivalent to event_base_loop(base, 0), which means that it will neither stop after the first batch of events (like event_base_loop with EVLOOP_ONCE does) nor return immediately if there is no event ready (like event_base_loop with EVLOOP_NONBLOCK does).

You may want to read the great book on libevent written by Nick Mathewson : http://www.wangafu.net/~nickm/libevent-book/Ref3_eventloop.html

Upvotes: 1

Related Questions