mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-26 00:25:59 +01:00
socket2: receive bytes to avoid endless loops
This commit is contained in:
parent
b32af6ebfb
commit
e4e653ada6
1 changed files with 24 additions and 2 deletions
|
@ -12,14 +12,15 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
CEventManager::CEventManager() {}
|
CEventManager::CEventManager() {}
|
||||||
|
|
||||||
int fdHandleWrite(int fd, uint32_t mask, void* data) {
|
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;
|
const auto ACCEPTEDFDS = (std::deque<std::pair<int, wl_event_source*>>*)data;
|
||||||
for (auto it = ACCEPTEDFDS->begin(); it != ACCEPTEDFDS->end();) {
|
for (auto it = ACCEPTEDFDS->begin(); it != ACCEPTEDFDS->end();) {
|
||||||
if (it->first == fd) {
|
if (it->first == fd) {
|
||||||
|
@ -29,6 +30,27 @@ int fdHandleWrite(int fd, uint32_t mask, void* data) {
|
||||||
it++;
|
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;
|
return 0;
|
||||||
|
|
Loading…
Reference in a new issue