MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ bind()

std::expected< UdsTransport::Bound, std::string > MayaFlux::Core::UdsTransport::bind ( Protocol::acceptor & acceptor,
const EndpointInfo & info )
static

Definition at line 91 of file UDSBackend.cpp.

93{
94 const auto acquired = Platform::acquire_unix_socket(source_of(info.local_path), socket_answers);
95 if (!acquired) {
96 return std::unexpected(refusal(acquired.error()));
97 }
98
99 Bound bound { .path = acquired->path };
100 const Protocol::endpoint endpoint(bound.path.string());
101 asio::error_code ec;
102
103 if (acceptor.open(endpoint.protocol(), ec)) {
104 return std::unexpected("failed to open acceptor: " + ec.message());
105 }
106 if (acceptor.bind(endpoint, ec)) {
107 return std::unexpected("failed to bind " + bound.path.string() + ": " + ec.message());
108 }
109
110 const auto fail = [&](const std::string& message) -> std::unexpected<std::string> {
111 asio::error_code close_ec;
112 (void)acceptor.close(close_ec);
113 release(bound);
114 return std::unexpected(message);
115 };
116
117 if (acceptor.listen(asio::socket_base::max_listen_connections, ec)) {
118 return fail("failed to listen on " + bound.path.string() + ": " + ec.message());
119 }
120 if (const auto restricted = Platform::restrict_unix_socket_to_owner(bound.path); !restricted) {
121 return fail(refusal(restricted.error()));
122 }
123
124 return bound;
125}
Acquired< UnixSocket > acquire_unix_socket(const UnixSocketSource &source, Probe &&is_alive)
Check that a Unix socket path can be bound, removing a stale socket file.
Acquired< void > restrict_unix_socket_to_owner(const std::filesystem::path &path)
Make a bound socket file usable by its owner only.
static void release(const Bound &bound)

References MayaFlux::Platform::acquire_unix_socket(), MayaFlux::Core::EndpointInfo::local_path, MayaFlux::Core::UdsTransport::Bound::path, release(), and MayaFlux::Platform::restrict_unix_socket_to_owner().

Here is the call graph for this function: