aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorvaxerski <[email protected]>2023-07-21 17:20:23 +0200
committervaxerski <[email protected]>2023-07-21 17:20:23 +0200
commit263b9c6e39c98a2790167db5251379e0acfd3e89 (patch)
treee7eac8499443b39dc0da587460b7d5ad9a53195b
parentd7e9eb65e233f216688377df43359a822a5d098f (diff)
downloadHyprland-263b9c6e39c98a2790167db5251379e0acfd3e89.tar.gz
Hyprland-263b9c6e39c98a2790167db5251379e0acfd3e89.zip
socket1: add a timeout for requests
-rw-r--r--src/debug/HyprCtl.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp
index 5c9b329e..03c556db 100644
--- a/src/debug/HyprCtl.cpp
+++ b/src/debug/HyprCtl.cpp
@@ -686,11 +686,10 @@ std::string dispatchRequest(std::string in) {
in = in.substr(in.find_first_of(' ') + 1);
const auto DISPATCHSTR = in.substr(0, in.find_first_of(' '));
-
- auto DISPATCHARG = std::string();
- if ((int) in.find_first_of(' ') != -1)
- DISPATCHARG = in.substr(in.find_first_of(' ') + 1);
+ auto DISPATCHARG = std::string();
+ if ((int)in.find_first_of(' ') != -1)
+ DISPATCHARG = in.substr(in.find_first_of(' ') + 1);
const auto DISPATCHER = g_pKeybindManager->m_mDispatchers.find(DISPATCHSTR);
if (DISPATCHER == g_pKeybindManager->m_mDispatchers.end())
@@ -1312,7 +1311,18 @@ int hyprCtlFDTick(int fd, uint32_t mask, void* data) {
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';
std::string request(readBuffer);