26 std::size_t MaxPacketSize = 512
29 static_assert(
sizeof(EventVariant) <= MaxPacketSize,
"EventVariant size exceeds MaxPacketSize");
30 static_assert(std::is_trivially_copyable_v<EventVariant>,
31 "UdsChannel EventVariant must be trivially copyable for datagram socket transmission.");
40 bool listen(
const std::string& socketPath,
bool nonBlocking =
true) noexcept
42 if (!_socket.
bind(socketPath)) {
55 bool connect(
const std::string& serverPath,
const std::string& clientPath =
"") noexcept
57 return _socket.
connect(serverPath, clientPath);
64 template <
typename EventType>
65 bool post(EventType&& event)
noexcept
67 EventVariant ev{std::forward<EventType>(event)};
68 const int bytesSent = _socket.
send(&ev,
sizeof(EventVariant));
69 return bytesSent ==
static_cast<int>(
sizeof(EventVariant));
75 bool tryPop(EventVariant& outEvent)
noexcept
77 const int bytesReceived = _socket.
receive(&outEvent,
sizeof(EventVariant));
78 return bytesReceived ==
static_cast<int>(
sizeof(EventVariant));
86 template <
typename SinkType>
87 std::size_t
pumpInto(
const SinkType& sink, std::size_t maxEvents = 0)
89 std::size_t count = 0;
92 sink.post(std::move(ev));
94 if (maxEvents > 0 && count >= maxEvents) {
108 [[nodiscard]]
bool isOpen() const noexcept
UNIX Domain Socket datagram listener and client implementation.
Standard lifecycle events (QuitEvent, ErrorEvent, TimerEvent).
Low-level RAII abstraction for UNIX Domain Datagram Sockets (AF_UNIX / SOCK_DGRAM)....
Definition DomainSocket.hpp:39
void setNonBlocking(bool nonBlocking) noexcept
Set socket non-blocking mode.
Definition DomainSocket.hpp:153
bool connect(const std::string &socketPath, const std::string &clientPath="") noexcept
Connect to a destination socket as a client.
Definition DomainSocket.hpp:111
void close() noexcept
Close socket and unlink bound file if server.
Definition DomainSocket.hpp:205
bool bind(const std::string &socketPath) noexcept
Bind socket to a filesystem path as a receiving server.
Definition DomainSocket.hpp:76
int send(const void *buffer, std::size_t length) noexcept
Send datagram packet over the connected socket.
Definition DomainSocket.hpp:176
bool isOpen() const noexcept
Check if socket descriptor is open.
Definition DomainSocket.hpp:221
int receive(void *buffer, std::size_t maxLength) noexcept
Receive datagram packet from socket.
Definition DomainSocket.hpp:192
Typed IPC channel operating over UNIX Domain Datagram Sockets. Provides boundary-preserving,...
Definition UdsChannel.hpp:28
bool listen(const std::string &socketPath, bool nonBlocking=true) noexcept
Start listening as an IPC server on a filesystem socket path.
Definition UdsChannel.hpp:40
DomainSocket & socket() noexcept
Access underlying DomainSocket instance.
Definition UdsChannel.hpp:114
bool tryPop(EventVariant &outEvent) noexcept
Try popping one pending datagram event from the socket (non-blocking).
Definition UdsChannel.hpp:75
bool connect(const std::string &serverPath, const std::string &clientPath="") noexcept
Connect as a client to a server socket path.
Definition UdsChannel.hpp:55
void close() noexcept
Close the socket connection and unlink socket file if server.
Definition UdsChannel.hpp:102
bool isOpen() const noexcept
Check if socket is open.
Definition UdsChannel.hpp:108
bool post(EventType &&event) noexcept
Post a typed event over the socket to the remote receiver.
Definition UdsChannel.hpp:65
std::size_t pumpInto(const SinkType &sink, std::size_t maxEvents=0)
Drain incoming UNIX domain socket events into a target event sink.
Definition UdsChannel.hpp:87
Definition DomainSocket.hpp:35
std::variant< QuitEvent, TickEvent, UpdateEvent, ErrorEvent, SignalEvent > DefaultEvents
Default variant list of core Corium events.
Definition Events.hpp:62