mirror of
https://github.com/hyprwm/Hyprland.git
synced 2025-08-24 16:33:48 -07:00
socket1: add a timeout for requests
This commit is contained in:
@@ -691,7 +691,6 @@ std::string dispatchRequest(std::string in) {
|
|||||||
if ((int)in.find_first_of(' ') != -1)
|
if ((int)in.find_first_of(' ') != -1)
|
||||||
DISPATCHARG = in.substr(in.find_first_of(' ') + 1);
|
DISPATCHARG = in.substr(in.find_first_of(' ') + 1);
|
||||||
|
|
||||||
|
|
||||||
const auto DISPATCHER = g_pKeybindManager->m_mDispatchers.find(DISPATCHSTR);
|
const auto DISPATCHER = g_pKeybindManager->m_mDispatchers.find(DISPATCHSTR);
|
||||||
if (DISPATCHER == g_pKeybindManager->m_mDispatchers.end())
|
if (DISPATCHER == g_pKeybindManager->m_mDispatchers.end())
|
||||||
return "Invalid dispatcher";
|
return "Invalid dispatcher";
|
||||||
@@ -1312,6 +1311,17 @@ int hyprCtlFDTick(int fd, uint32_t mask, void* data) {
|
|||||||
|
|
||||||
char readBuffer[1024];
|
char readBuffer[1024];
|
||||||
|
|
||||||
|
fd_set fdset;
|
||||||
|
FD_ZERO(&fdset);
|
||||||
|
FD_SET(ACCEPTEDCONNECTION, &fdset);
|
||||||
|
timeval timeout = {.tv_sec = 0, .tv_usec = 5000};
|
||||||
|
auto success = select(ACCEPTEDCONNECTION + 1, &fdset, nullptr, nullptr, &timeout);
|
||||||
|
|
||||||
|
if (success <= 0) {
|
||||||
|
close(ACCEPTEDCONNECTION);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
auto messageSize = read(ACCEPTEDCONNECTION, readBuffer, 1024);
|
auto messageSize = read(ACCEPTEDCONNECTION, readBuffer, 1024);
|
||||||
readBuffer[messageSize == 1024 ? 1023 : messageSize] = '\0';
|
readBuffer[messageSize == 1024 ? 1023 : messageSize] = '\0';
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user