mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-26 21:45:59 +01:00
hyprctl: move to CFileDescriptor
use CFileDescriptor instead of manual fd handling.
This commit is contained in:
parent
940f7aa990
commit
ee1e636d08
2 changed files with 10 additions and 9 deletions
|
@ -1668,8 +1668,6 @@ CHyprCtl::CHyprCtl() {
|
||||||
CHyprCtl::~CHyprCtl() {
|
CHyprCtl::~CHyprCtl() {
|
||||||
if (m_eventSource)
|
if (m_eventSource)
|
||||||
wl_event_source_remove(m_eventSource);
|
wl_event_source_remove(m_eventSource);
|
||||||
if (m_iSocketFD >= 0)
|
|
||||||
close(m_iSocketFD);
|
|
||||||
if (!m_socketPath.empty())
|
if (!m_socketPath.empty())
|
||||||
unlink(m_socketPath.c_str());
|
unlink(m_socketPath.c_str());
|
||||||
}
|
}
|
||||||
|
@ -1831,7 +1829,7 @@ int hyprCtlFDTick(int fd, uint32_t mask, void* data) {
|
||||||
sockaddr_in clientAddress;
|
sockaddr_in clientAddress;
|
||||||
socklen_t clientSize = sizeof(clientAddress);
|
socklen_t clientSize = sizeof(clientAddress);
|
||||||
|
|
||||||
const auto ACCEPTEDCONNECTION = accept4(g_pHyprCtl->m_iSocketFD, (sockaddr*)&clientAddress, &clientSize, SOCK_CLOEXEC);
|
const auto ACCEPTEDCONNECTION = accept4(g_pHyprCtl->m_iSocketFD.get(), (sockaddr*)&clientAddress, &clientSize, SOCK_CLOEXEC);
|
||||||
|
|
||||||
std::array<char, 1024> readBuffer;
|
std::array<char, 1024> readBuffer;
|
||||||
|
|
||||||
|
@ -1888,9 +1886,9 @@ int hyprCtlFDTick(int fd, uint32_t mask, void* data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHyprCtl::startHyprCtlSocket() {
|
void CHyprCtl::startHyprCtlSocket() {
|
||||||
m_iSocketFD = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
|
m_iSocketFD = CFileDescriptor(socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0));
|
||||||
|
|
||||||
if (m_iSocketFD < 0) {
|
if (!m_iSocketFD.isValid()) {
|
||||||
Debug::log(ERR, "Couldn't start the Hyprland Socket. (1) IPC will not work.");
|
Debug::log(ERR, "Couldn't start the Hyprland Socket. (1) IPC will not work.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1901,15 +1899,15 @@ void CHyprCtl::startHyprCtlSocket() {
|
||||||
|
|
||||||
strcpy(SERVERADDRESS.sun_path, m_socketPath.c_str());
|
strcpy(SERVERADDRESS.sun_path, m_socketPath.c_str());
|
||||||
|
|
||||||
if (bind(m_iSocketFD, (sockaddr*)&SERVERADDRESS, SUN_LEN(&SERVERADDRESS)) < 0) {
|
if (bind(m_iSocketFD.get(), (sockaddr*)&SERVERADDRESS, SUN_LEN(&SERVERADDRESS)) < 0) {
|
||||||
Debug::log(ERR, "Couldn't start the Hyprland Socket. (2) IPC will not work.");
|
Debug::log(ERR, "Couldn't start the Hyprland Socket. (2) IPC will not work.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 10 max queued.
|
// 10 max queued.
|
||||||
listen(m_iSocketFD, 10);
|
listen(m_iSocketFD.get(), 10);
|
||||||
|
|
||||||
Debug::log(LOG, "Hypr socket started at {}", m_socketPath);
|
Debug::log(LOG, "Hypr socket started at {}", m_socketPath);
|
||||||
|
|
||||||
m_eventSource = wl_event_loop_add_fd(g_pCompositor->m_sWLEventLoop, m_iSocketFD, WL_EVENT_READABLE, hyprCtlFDTick, nullptr);
|
m_eventSource = wl_event_loop_add_fd(g_pCompositor->m_sWLEventLoop, m_iSocketFD.get(), WL_EVENT_READABLE, hyprCtlFDTick, nullptr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,9 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include "../helpers/MiscFunctions.hpp"
|
#include "../helpers/MiscFunctions.hpp"
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <hyprutils/os/FileDescriptor.hpp>
|
||||||
|
|
||||||
|
using namespace Hyprutils::OS;
|
||||||
|
|
||||||
// exposed for main.cpp
|
// exposed for main.cpp
|
||||||
std::string systemInfoRequest(eHyprCtlOutputFormat format, std::string request);
|
std::string systemInfoRequest(eHyprCtlOutputFormat format, std::string request);
|
||||||
|
@ -19,7 +22,7 @@ class CHyprCtl {
|
||||||
void unregisterCommand(const SP<SHyprCtlCommand>& cmd);
|
void unregisterCommand(const SP<SHyprCtlCommand>& cmd);
|
||||||
std::string getReply(std::string);
|
std::string getReply(std::string);
|
||||||
|
|
||||||
int m_iSocketFD = -1;
|
CFileDescriptor m_iSocketFD;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
bool all = false;
|
bool all = false;
|
||||||
|
|
Loading…
Reference in a new issue