diff options
author | vaxerski <[email protected]> | 2023-04-08 23:14:12 +0100 |
---|---|---|
committer | vaxerski <[email protected]> | 2023-04-08 23:14:12 +0100 |
commit | e4e653ada6fc729efad3f6a0d49cf72b94c43b6c (patch) | |
tree | 58664ec411137cdc967f4b5d4b518933e7981407 | |
parent | b32af6ebfb5ea3ffc16cbf07a6cdbaa6c486ba58 (diff) | |
download | Hyprland-e4e653ada6fc729efad3f6a0d49cf72b94c43b6c.tar.gz Hyprland-e4e653ada6fc729efad3f6a0d49cf72b94c43b6c.zip |
socket2: receive bytes to avoid endless loops
-rw-r--r-- | src/managers/EventManager.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/managers/EventManager.cpp b/src/managers/EventManager.cpp index 81acd379..3fd63fcb 100644 --- a/src/managers/EventManager.cpp +++ b/src/managers/EventManager.cpp @@ -12,14 +12,15 @@ #include <sys/types.h> #include <sys/un.h> #include <unistd.h> +#include <sys/ioctl.h> #include <string> CEventManager::CEventManager() {} int fdHandleWrite(int fd, uint32_t mask, void* data) { - if (mask & WL_EVENT_ERROR || mask & WL_EVENT_HANGUP) { - // remove, hanged up + + auto removeFD = [&](int fd) -> void { const auto ACCEPTEDFDS = (std::deque<std::pair<int, wl_event_source*>>*)data; for (auto it = ACCEPTEDFDS->begin(); it != ACCEPTEDFDS->end();) { if (it->first == fd) { @@ -29,6 +30,27 @@ int fdHandleWrite(int fd, uint32_t mask, void* data) { it++; } } + }; + + if (mask & WL_EVENT_ERROR || mask & WL_EVENT_HANGUP) { + // remove, hanged up + removeFD(fd); + return 0; + } + + int availableBytes; + if (ioctl(fd, FIONREAD, &availableBytes) == -1) { + Debug::log(ERR, "fd %d sent invalid data (1)", fd); + removeFD(fd); + return 0; + } + + char buf[availableBytes]; + const auto RECEIVED = recv(fd, buf, availableBytes, 0); + if (RECEIVED == -1) { + Debug::log(ERR, "fd %d sent invalid data (2)", fd); + removeFD(fd); + return 0; } return 0; |