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 #include #include +#include #include 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>*)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;