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

◆ send()

bool MayaFlux::Core::UDPBackend::send ( uint64_t  endpoint_id,
const uint8_t *  data,
size_t  size 
)
overridevirtual

Send data through an endpoint.

Parameters
endpoint_idTarget endpoint.
dataPointer to payload bytes.
sizePayload size in bytes.
Returns
true if the send was accepted (queued or completed).

For UDP: sends a single datagram via sendto(). Non-blocking. For TCP: writes framed message. May block briefly if kernel send buffer is full. For SHM: writes into the shared segment.

Implements MayaFlux::Core::INetworkBackend.

Definition at line 186 of file UDPBackend.cpp.

187{
188 std::shared_lock lock(m_endpoints_mutex);
189 auto it = m_endpoints.find(endpoint_id);
190 if (it == m_endpoints.end()) {
191 return false;
192 }
193
194 auto& record = it->second;
195 if (!record.has_default_remote) {
197 "UDP endpoint {} has no default remote target", endpoint_id);
198 return false;
199 }
200
201 auto buf = std::make_shared<std::vector<uint8_t>>(data, data + size);
202 auto remote = record.default_remote;
203 auto& socket = record.socket_state->socket;
204
205 socket.async_send_to(
206 asio::buffer(*buf), remote,
207 [buf, endpoint_id](const asio::error_code& ec, size_t /*bytes_sent*/) {
208 if (ec) {
210 "UDP send failed on endpoint {}: {}", endpoint_id, ec.message());
211 }
212 });
213
214 return true;
215}
#define MF_WARN(comp, ctx,...)
Range size
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 MayaFlux::Journal::Core, m_endpoints, m_endpoints_mutex, MF_WARN, MayaFlux::Journal::NetworkBackend, and size.