refactor(niri): use shared ScopedFd utility

Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
Austin Horstman
2026-03-02 08:21:17 -06:00
parent e83ab7609c
commit 2ff77fb73d

View File

@@ -13,6 +13,7 @@
#include <string> #include <string>
#include <thread> #include <thread>
#include "util/scoped_fd.hpp"
#include "giomm/datainputstream.h" #include "giomm/datainputstream.h"
#include "giomm/dataoutputstream.h" #include "giomm/dataoutputstream.h"
#include "giomm/unixinputstream.h" #include "giomm/unixinputstream.h"
@@ -30,7 +31,7 @@ int IPC::connectToSocket() {
} }
struct sockaddr_un addr; struct sockaddr_un addr;
int socketfd = socket(AF_UNIX, SOCK_STREAM, 0); util::ScopedFd socketfd(socket(AF_UNIX, SOCK_STREAM, 0));
if (socketfd == -1) { if (socketfd == -1) {
throw std::runtime_error("socketfd failed"); throw std::runtime_error("socketfd failed");
@@ -45,11 +46,10 @@ int IPC::connectToSocket() {
int l = sizeof(struct sockaddr_un); int l = sizeof(struct sockaddr_un);
if (connect(socketfd, (struct sockaddr*)&addr, l) == -1) { if (connect(socketfd, (struct sockaddr*)&addr, l) == -1) {
close(socketfd);
throw std::runtime_error("unable to connect"); throw std::runtime_error("unable to connect");
} }
return socketfd; return socketfd.release();
} }
void IPC::startIPC() { void IPC::startIPC() {
@@ -235,7 +235,7 @@ void IPC::unregisterForIPC(EventHandler* ev_handler) {
} }
Json::Value IPC::send(const Json::Value& request) { Json::Value IPC::send(const Json::Value& request) {
int socketfd = connectToSocket(); util::ScopedFd socketfd(connectToSocket());
auto unix_istream = Gio::UnixInputStream::create(socketfd, true); auto unix_istream = Gio::UnixInputStream::create(socketfd, true);
auto unix_ostream = Gio::UnixOutputStream::create(socketfd, false); auto unix_ostream = Gio::UnixOutputStream::create(socketfd, false);