MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
UDSBackend.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "StreamBackend.hpp"
4
5#include <asio/local/stream_protocol.hpp>
6
7namespace MayaFlux::Core {
8
9/**
10 * @struct UdsTransport
11 * @brief StreamBackend policy for Unix domain sockets
12 *
13 * An endpoint with a remote_path connects to it. An endpoint with only a
14 * local_path listens on it. A path holding a directory separator is used as
15 * given, and a bare file name is placed in the user's runtime directory.
16 *
17 * A listener acquires its path before binding: a stale socket file that nothing
18 * answers on is replaced, a live one or anything that is not a socket refuses the
19 * endpoint. On POSIX the bound file is restricted to its owner, and the file is
20 * removed when the listener closes.
21 */
23 using Protocol = asio::local::stream_protocol;
24 using Stream = Protocol::socket;
26
27 struct Bound {
28 std::filesystem::path path;
29 };
30
31 static constexpr bool listens = true;
34 static constexpr std::string_view label = "UDS";
35 static constexpr std::string_view name = "UDS (Asio)";
36
37 static bool is_listener(const EndpointInfo& info);
38 static std::expected<Bound, std::string> bind(Protocol::acceptor& acceptor, const EndpointInfo& info);
39 static void release(const Bound& bound);
40 static std::expected<Protocol::endpoint, std::string> connect_target(const EndpointInfo& info);
41 static void describe_accepted(const Protocol::socket& socket, const EndpointInfo& listener, EndpointInfo& accepted);
42 static std::string describe(const EndpointInfo& info);
43 static std::string peer_label(const EndpointInfo& info);
44};
45
46/**
47 * @class UDSBackend
48 * @brief Reliable length-prefixed message transport over Unix domain sockets
49 *
50 * The same-machine counterpart of TCPBackend: one socket path is one endpoint,
51 * with the same framing, listener and connection model, reconnection and
52 * accepted-connection announcements. See StreamBackend for the shared behaviour
53 * and UdsTransport for how a path is resolved and secured.
54 *
55 * @code
56 * EndpointInfo server;
57 * server.role = EndpointRole::RECEIVE;
58 * server.local_path = "mayaflux-control.sock";
59 * auto listen_id = uds.open_endpoint(server);
60 *
61 * EndpointInfo client;
62 * client.role = EndpointRole::BIDIRECTIONAL;
63 * client.remote_path = "mayaflux-control.sock";
64 * auto ep_id = uds.open_endpoint(client);
65 * @endcode
66 */
68
69#ifdef MAYAFLUX_EXPORTS
70extern template class StreamBackend<UdsTransport>;
71#else
72extern template class MAYAFLUX_API StreamBackend<UdsTransport>;
73#endif
74
75} // namespace MayaFlux::Core
Connection-oriented reliable message transport over an Asio stream protocol.
NetworkTransport
Identifies the transport protocol a backend implements.
StreamBackend< UdsTransport > UDSBackend
FramingPolicy
How messages are delimited on the wire.
Describes one logical send/receive endpoint managed by a backend.
Configuration for the Unix domain socket transport backend.
static constexpr FramingPolicy automatic_framing
static std::string describe(const EndpointInfo &info)
static constexpr bool listens
static std::expected< Bound, std::string > bind(Protocol::acceptor &acceptor, const EndpointInfo &info)
static std::expected< Protocol::endpoint, std::string > connect_target(const EndpointInfo &info)
static bool is_listener(const EndpointInfo &info)
asio::local::stream_protocol Protocol
static void release(const Bound &bound)
static void describe_accepted(const Protocol::socket &socket, const EndpointInfo &listener, EndpointInfo &accepted)
static constexpr std::string_view name
static constexpr std::string_view label
static std::string peer_label(const EndpointInfo &info)
StreamBackend policy for Unix domain sockets.