mirror of
https://github.com/hyprwm/Hyprland
synced 2024-12-23 09:29:49 +01:00
socket1: add a timeout for requests
This commit is contained in:
parent
d7e9eb65e2
commit
263b9c6e39
1 changed files with 15 additions and 5 deletions
|
@ -687,11 +687,10 @@ std::string dispatchRequest(std::string in) {
|
||||||
|
|
||||||
const auto DISPATCHSTR = in.substr(0, in.find_first_of(' '));
|
const auto DISPATCHSTR = in.substr(0, in.find_first_of(' '));
|
||||||
|
|
||||||
auto DISPATCHARG = std::string();
|
auto DISPATCHARG = std::string();
|
||||||
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,7 +1311,18 @@ int hyprCtlFDTick(int fd, uint32_t mask, void* data) {
|
||||||
|
|
||||||
char readBuffer[1024];
|
char readBuffer[1024];
|
||||||
|
|
||||||
auto messageSize = read(ACCEPTEDCONNECTION, 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);
|
||||||
readBuffer[messageSize == 1024 ? 1023 : messageSize] = '\0';
|
readBuffer[messageSize == 1024 ? 1023 : messageSize] = '\0';
|
||||||
|
|
||||||
std::string request(readBuffer);
|
std::string request(readBuffer);
|
||||||
|
|
Loading…
Reference in a new issue