summaryrefslogtreecommitdiff
path: root/src/debug/HyprCtl.cpp
diff options
context:
space:
mode:
authorvaxerski <43317083+vaxerski@users.noreply.github.com>2022-03-30 16:24:42 +0200
committervaxerski <43317083+vaxerski@users.noreply.github.com>2022-03-30 16:24:42 +0200
commitd01c7c07d8d8684bd9aa41298a5122212c01f6ce (patch)
tree8ae56ebc90fc87f26f09736da98b02053318bbb8 /src/debug/HyprCtl.cpp
parentae3d1ec3adccac586f90146b900b5f6af0199350 (diff)
Fix IPC being wonky
Diffstat (limited to 'src/debug/HyprCtl.cpp')
-rw-r--r--src/debug/HyprCtl.cpp29
1 files changed, 13 insertions, 16 deletions
diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp
index 59f1386c..450394f9 100644
--- a/src/debug/HyprCtl.cpp
+++ b/src/debug/HyprCtl.cpp
@@ -8,6 +8,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
+#include <errno.h>
#include <string>
@@ -84,9 +85,9 @@ std::string layersRequest() {
}
void HyprCtl::startHyprCtlSocket() {
- int port = 9187;
-
std::thread([&]() {
+ uint16_t connectPort = 9187;
+
const auto SOCKET = socket(AF_INET, SOCK_STREAM, 0);
if (SOCKET < 0) {
@@ -94,23 +95,19 @@ void HyprCtl::startHyprCtlSocket() {
return;
}
- sockaddr_in SERVERADDRESS = {.sin_family = AF_INET, .sin_port = port, .sin_addr = (in_addr)INADDR_ANY};
-
- bool bound = false;
+ sockaddr_in SERVERADDRESS = {.sin_family = AF_INET, .sin_port = connectPort, .sin_addr = (in_addr)INADDR_ANY};
- while (port++ < 9999) {
- if (bind(SOCKET, (sockaddr*)&SERVERADDRESS, sizeof(SERVERADDRESS)) >= 0) {
- bound = true;
+ while(connectPort < 11000) {
+ if (bind(SOCKET, (sockaddr*)&SERVERADDRESS, sizeof(SERVERADDRESS)) < 0) {
+ Debug::log(LOG, "IPC: Port %d failed with an error: %s", connectPort, strerror(errno));
+ } else {
break;
}
- SERVERADDRESS = {.sin_family = AF_INET, .sin_port = port, .sin_addr = (in_addr)INADDR_ANY};
- }
-
- if (!bound) {
- Debug::log(ERR, "Couldn't start the Hyprland Socket. (2) IPC will not work.");
- return;
+ connectPort++;
+ SERVERADDRESS.sin_port = connectPort;
}
+
// 10 max queued.
listen(SOCKET, 10);
@@ -120,11 +117,11 @@ void HyprCtl::startHyprCtlSocket() {
char readBuffer[1024] = {0};
- Debug::log(LOG, "Hypr socket started on port %i", SERVERADDRESS.sin_port);
+ Debug::log(LOG, "Hypr socket started on port %i", connectPort);
std::string cmd = "rm -f /tmp/hypr/.socket";
system(cmd.c_str()); // forgive me for using system() but it works and it doesnt matter here that much
- cmd = "echo \"" + std::to_string(SERVERADDRESS.sin_port) + "\" > /tmp/hypr/.socket";
+ cmd = "echo \"" + std::to_string(connectPort) + "\" > /tmp/hypr/.socket";
system(cmd.c_str());
while(1) {