mirror of
https://github.com/Alexays/Waybar.git
synced 2026-04-02 21:03:32 +00:00
refactor(niri): use shared ScopedFd utility
Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
@ -13,6 +13,7 @@
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
#include "util/scoped_fd.hpp"
|
||||
#include "giomm/datainputstream.h"
|
||||
#include "giomm/dataoutputstream.h"
|
||||
#include "giomm/unixinputstream.h"
|
||||
@ -30,7 +31,7 @@ int IPC::connectToSocket() {
|
||||
}
|
||||
|
||||
struct sockaddr_un addr;
|
||||
int socketfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
util::ScopedFd socketfd(socket(AF_UNIX, SOCK_STREAM, 0));
|
||||
|
||||
if (socketfd == -1) {
|
||||
throw std::runtime_error("socketfd failed");
|
||||
@ -45,11 +46,10 @@ int IPC::connectToSocket() {
|
||||
int l = sizeof(struct sockaddr_un);
|
||||
|
||||
if (connect(socketfd, (struct sockaddr*)&addr, l) == -1) {
|
||||
close(socketfd);
|
||||
throw std::runtime_error("unable to connect");
|
||||
}
|
||||
|
||||
return socketfd;
|
||||
return socketfd.release();
|
||||
}
|
||||
|
||||
void IPC::startIPC() {
|
||||
@ -235,7 +235,7 @@ void IPC::unregisterForIPC(EventHandler* ev_handler) {
|
||||
}
|
||||
|
||||
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_ostream = Gio::UnixOutputStream::create(socketfd, false);
|
||||
|
||||
Reference in New Issue
Block a user