From 228bb998f69c01e0c92d4c4f6cbe51b9304f5fd5 Mon Sep 17 00:00:00 2001 From: unai_71 Date: Tue, 10 Mar 2026 17:50:13 +0000 Subject: [PATCH] fix: forgot to add the source file to the commit... disastrous --- src/core/UnixIpcBridge.cxx | 49 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/core/UnixIpcBridge.cxx diff --git a/src/core/UnixIpcBridge.cxx b/src/core/UnixIpcBridge.cxx new file mode 100644 index 0000000..5ef4efe --- /dev/null +++ b/src/core/UnixIpcBridge.cxx @@ -0,0 +1,49 @@ +// UnixIpcBridge.cxx +// SPDX-License-Identifier: GPL-3.0-only +// Author: Unai Blazquez +#include "UnixIpcBridge.hpp" + +#include +#include + +UnixIpcBridge::UnixIpcBridge(const std::string& socket_path) + : m_socket_path(socket_path) +{ +} + +void UnixIpcBridge::send(int value) +{ + connect_to_consumer(); + + ssize_t n = ::send(m_socket_fd, &value, sizeof(value), 0); + if (n != sizeof(value)) + { + close(m_socket_fd); + m_socket_fd = -1; + throw std::runtime_error("UnixIpcBridge::send: failed to write value"); + } + + close(m_socket_fd); + m_socket_fd = -1; +} + +void UnixIpcBridge::connect_to_consumer() +{ + m_socket_fd = socket(AF_UNIX, SOCK_STREAM, 0); + if (m_socket_fd < 0) + { + throw std::runtime_error("UnixIpcBridge: socket() failed"); + } + + struct sockaddr_un addr = {}; + addr.sun_family = AF_UNIX; + std::strncpy(addr.sun_path, m_socket_path.c_str(), sizeof(addr.sun_path) - 1); + + if (connect(m_socket_fd, reinterpret_cast(&addr), sizeof(addr)) < + 0) + { + close(m_socket_fd); + m_socket_fd = -1; + throw std::runtime_error("UnixIpcBridge: connect() failed"); + } +} -- 2.49.1