aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorVaxry <[email protected]>2023-11-13 16:30:37 +0000
committerVaxry <[email protected]>2023-11-13 16:30:37 +0000
commit016a7a9c9b1ca1f04a8d85c56699f6d6b77258a0 (patch)
treea251c98faa123281f669b2c2ca53f01206c76843
parent2e26542e3bba3533e71e13f2257823d96da2318a (diff)
downloadHyprland-016a7a9c9b1ca1f04a8d85c56699f6d6b77258a0.tar.gz
Hyprland-016a7a9c9b1ca1f04a8d85c56699f6d6b77258a0.zip
hyprctl: use a rolling buffer for reading requests
fixes #3846
-rw-r--r--src/debug/HyprCtl.cpp25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp
index c09251a8..217895b1 100644
--- a/src/debug/HyprCtl.cpp
+++ b/src/debug/HyprCtl.cpp
@@ -1385,14 +1385,14 @@ int hyprCtlFDTick(int fd, uint32_t mask, void* data) {
if (mask & WL_EVENT_ERROR || mask & WL_EVENT_HANGUP)
return 0;
- sockaddr_in clientAddress;
- socklen_t clientSize = sizeof(clientAddress);
+ sockaddr_in clientAddress;
+ socklen_t clientSize = sizeof(clientAddress);
- const auto ACCEPTEDCONNECTION = accept4(HyprCtl::iSocketFD, (sockaddr*)&clientAddress, &clientSize, SOCK_CLOEXEC);
+ const auto ACCEPTEDCONNECTION = accept4(HyprCtl::iSocketFD, (sockaddr*)&clientAddress, &clientSize, SOCK_CLOEXEC);
- char readBuffer[1024];
+ std::array<char, 1024> readBuffer;
- fd_set fdset;
+ fd_set fdset;
FD_ZERO(&fdset);
FD_SET(ACCEPTEDCONNECTION, &fdset);
timeval timeout = {.tv_sec = 0, .tv_usec = 5000};
@@ -1403,10 +1403,17 @@ int hyprCtlFDTick(int fd, uint32_t mask, void* data) {
return 0;
}
- auto messageSize = read(ACCEPTEDCONNECTION, readBuffer, 1024);
- readBuffer[messageSize == 1024 ? 1023 : messageSize] = '\0';
-
- std::string request(readBuffer);
+ std::string request;
+ while (true) {
+ readBuffer.fill(0);
+ auto messageSize = read(ACCEPTEDCONNECTION, readBuffer.data(), 1023);
+ if (messageSize < 1)
+ break;
+ std::string recvd = readBuffer.data();
+ request += recvd;
+ if (messageSize < 1023)
+ break;
+ }
std::string reply = "";