From e6b9a1d982493a9b2431099b906c704fd7cb46d2 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 17 Aug 2014 15:58:42 +0100 Subject: [PATCH] Get forced file descriptors after calling poll That way, we do not wait for the next poll to finish before servicing forced fd triggered by a signal that interupted the poll call. --- src/event_manager.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/event_manager.cc b/src/event_manager.cc index 152791ad..8f7395d4 100644 --- a/src/event_manager.cc +++ b/src/event_manager.cc @@ -52,8 +52,6 @@ void EventManager::handle_next_events() events.reserve(m_fd_watchers.size()); for (auto& watcher : m_fd_watchers) events.emplace_back(pollfd{ watcher->fd(), POLLIN | POLLPRI, 0 }); - std::vector forced; - std::swap(forced, m_forced_fd); TimePoint next_timer = TimePoint::max(); for (auto& timer : m_timers) @@ -64,6 +62,12 @@ void EventManager::handle_next_events() using namespace std::chrono; auto timeout = duration_cast(next_timer - Clock::now()).count(); poll(events.data(), events.size(), timeout < INT_MAX ? (int)timeout : INT_MAX); + + // gather forced fds *after* poll, so that signal handlers can write to + // m_forced_fd, interupt poll, and directly be serviced. + std::vector forced; + std::swap(forced, m_forced_fd); + for (size_t i = 0; i < events.size(); ++i) { auto& event = events[i];