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

◆ open_endpoint()

uint64_t MayaFlux::Core::UDPBackend::open_endpoint ( const EndpointInfo info)
overridevirtual

Open a new endpoint.

Parameters
infoEndpoint configuration with id pre-assigned by subsystem.
Returns
The endpoint id on success, or 0 on failure.

The subsystem assigns the id before calling this. The backend stores and uses it for subsequent operations.

For UDP: binds a local port and/or stores a default remote target. For TCP: connects to a remote host, or begins listening on a port. Outbound connect may block. Use co_open_endpoint on the service for non-blocking connect. For SHM: opens or creates a named shared memory segment.

Implements MayaFlux::Core::INetworkBackend.

Definition at line 91 of file UDPBackend.cpp.

92{
93 uint16_t local_port = info.local_port;
94
95 if (local_port == 0 && info.role == EndpointRole::SEND) {
96 local_port = 0;
97 } else if (local_port == 0) {
98 local_port = m_config.default_receive_port;
99 }
100
101 auto* sock = acquire_socket(local_port);
102 if (!sock) {
103 return 0;
104 }
105
106 EndpointRecord record;
107 record.info = info;
108 record.socket_state = sock;
109
110 if (!info.remote_address.empty() && info.remote_port > 0) {
111 asio::error_code ec;
112 auto addr = asio::ip::make_address(info.remote_address, ec);
113 if (ec) {
115 "Invalid remote address '{}': {}", info.remote_address, ec.message());
116 release_socket(local_port);
117 return 0;
118 }
119 record.default_remote = asio::ip::udp::endpoint(addr, info.remote_port);
120 record.has_default_remote = true;
121 }
122
123 record.info.state = EndpointState::OPEN;
124
125 {
126 std::unique_lock lock(m_endpoints_mutex);
127 m_endpoints[info.id] = std::move(record);
128 }
129
131
133 "UDP endpoint {} opened (local:{}, remote:{}:{})",
134 info.id, local_port, info.remote_address, info.remote_port);
135
136 return info.id;
137}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
void transition_state(EndpointRecord &record, EndpointState new_state)
void release_socket(uint16_t local_port)
Decrement ref_count for a socket.
SocketState * acquire_socket(uint16_t local_port)
Get or create a socket bound to local_port.
std::unordered_map< uint64_t, EndpointRecord > m_endpoints
std::shared_mutex m_endpoints_mutex
@ NetworkBackend
Network transport backend (UDP, TCP, SHM)
@ Core
Core engine, backend, subsystems.

References acquire_socket(), MayaFlux::Journal::Core, MayaFlux::Core::UDPBackendInfo::default_receive_port, MayaFlux::Core::UDPBackend::EndpointRecord::default_remote, MayaFlux::Core::UDPBackend::EndpointRecord::has_default_remote, MayaFlux::Core::EndpointInfo::id, MayaFlux::Core::UDPBackend::EndpointRecord::info, MayaFlux::Core::EndpointInfo::local_port, m_config, m_endpoints, m_endpoints_mutex, MF_ERROR, MF_INFO, MayaFlux::Journal::NetworkBackend, MayaFlux::Core::OPEN, release_socket(), MayaFlux::Core::EndpointInfo::remote_address, MayaFlux::Core::EndpointInfo::remote_port, MayaFlux::Core::EndpointInfo::role, MayaFlux::Core::SEND, MayaFlux::Core::UDPBackend::EndpointRecord::socket_state, MayaFlux::Core::EndpointInfo::state, and transition_state().

+ Here is the call graph for this function: