diff options
Diffstat (limited to '')
-rw-r--r-- | src/event/Loop.cxx | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/src/event/Loop.cxx b/src/event/Loop.cxx index 5aa24aea2..f7b3df022 100644 --- a/src/event/Loop.cxx +++ b/src/event/Loop.cxx @@ -20,7 +20,7 @@ #include "config.h" #include "Loop.hxx" -#ifdef USE_EPOLL +#ifdef USE_INTERNAL_EVENTLOOP #include "system/Clock.hxx" #include "TimeoutMonitor.hxx" @@ -33,7 +33,6 @@ EventLoop::EventLoop(Default) :SocketMonitor(*this), now_ms(::MonotonicClockMS()), quit(false), - n_events(0), thread(ThreadId::Null()) { SocketMonitor::Open(wake_fd.Get()); @@ -58,19 +57,18 @@ EventLoop::Break() AddCall([this]() { Break(); }); } -void -EventLoop::Abandon(SocketMonitor &m) +bool +EventLoop::Abandon(int _fd, SocketMonitor &m) { - for (unsigned i = 0, n = n_events; i < n; ++i) - if (events[i].data.ptr == &m) - events[i].events = 0; + poll_result.Clear(&m); + return poll_group.Abandon(_fd); } bool EventLoop::RemoveFD(int _fd, SocketMonitor &m) { - Abandon(m); - return epoll.Remove(_fd); + poll_result.Clear(&m); + return poll_group.Remove(_fd); } void @@ -115,7 +113,7 @@ EventLoop::Run() assert(thread.IsNull()); thread = ThreadId::GetCurrent(); -#ifdef USE_EPOLL +#ifdef USE_INTERNAL_EVENTLOOP assert(!quit); do { @@ -164,37 +162,37 @@ EventLoop::Run() /* wait for new event */ - const int n = epoll.Wait(events, MAX_EVENTS, timeout_ms); - n_events = std::max(n, 0); + poll_group.ReadEvents(poll_result, timeout_ms); now_ms = ::MonotonicClockMS(); assert(!quit); /* invoke sockets */ - - for (int i = 0; i < n; ++i) { - const auto &e = events[i]; - - if (e.events != 0) { - SocketMonitor &m = *(SocketMonitor *)e.data.ptr; - m.Dispatch(e.events); + for (int i = 0; i < poll_result.GetSize(); ++i) { + auto events = poll_result.GetEvents(i); + if (events != 0) { + auto m = (SocketMonitor *)poll_result.GetObject(i); + m->Dispatch(events); if (quit) break; } } - n_events = 0; + poll_result.Reset(); + } while (!quit); -#else +#endif + +#ifdef USE_GLIB_EVENTLOOP g_main_loop_run(loop); #endif assert(thread.IsInside()); } -#ifdef USE_EPOLL +#ifdef USE_INTERNAL_EVENTLOOP void EventLoop::AddCall(std::function<void()> &&f) @@ -229,7 +227,9 @@ EventLoop::OnSocketReady(gcc_unused unsigned flags) return true; } -#else +#endif + +#ifdef USE_GLIB_EVENTLOOP guint EventLoop::AddIdle(GSourceFunc function, gpointer data) |