From 34fb22b162cf78d97c39804da1e647297121b7e4 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Thu, 23 Jul 2026 19:23:26 +0200 Subject: [PATCH] core: fix loop hangup detection --- src/core/PortalManager.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/core/PortalManager.cpp b/src/core/PortalManager.cpp index fe5a27d..5dc98d4 100644 --- a/src/core/PortalManager.cpp +++ b/src/core/PortalManager.cpp @@ -349,13 +349,16 @@ void CPortalManager::startEventLoop() { if (ret < 0) { Debug::log(CRIT, "[core] Polling fds failed with {}", strerror(errno)); g_pPortalManager->terminate(); + break; } - for (size_t i = 0; i < 3; ++i) { - if (m_sEventLoopInternals.pollFds.data()->revents & POLLHUP) { - Debug::log(CRIT, "[core] Disconnected from pollfd id {}", i); - g_pPortalManager->terminate(); - } + for (size_t i = 0; i < m_sEventLoopInternals.pollFds.size(); ++i) { + if (!(m_sEventLoopInternals.pollFds[i].revents & (POLLHUP | POLLERR | POLLNVAL))) + continue; + + Debug::log(CRIT, "[core] Disconnected from pollfd id {}", i); + g_pPortalManager->terminate(); + break; } if (m_bTerminate) @@ -557,7 +560,7 @@ void CPortalManager::addTimer(const CTimer& timer) { } void CPortalManager::addFdToEventLoop(int fd, short events, std::function callback) { - m_sEventLoopInternals.pollFds.emplace_back(pollfd{.fd = fd, .events = POLLIN}); + m_sEventLoopInternals.pollFds.emplace_back(pollfd{.fd = fd, .events = events}); if (callback == nullptr) return;