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

◆ on_receive()

void MayaFlux::Core::UDPBackend::on_receive ( SocketState state,
const asio::error_code &  ec,
size_t  bytes_received 
)
private

Completion handler for async_receive_from.

Fires the receive callback with the endpoint id resolved from the sender address, then resubmits async_receive_from.

Definition at line 363 of file UDPBackend.cpp.

364{
365 if (ec) {
366 if (ec == asio::error::operation_aborted) {
367 return;
368 }
370 "UDP receive error on port {}: {}", state.local_port, ec.message());
371 start_receive_loop(state);
372 return;
373 }
374
375 if (m_receive_callback && bytes_received > 0) {
376 std::string sender_str = state.sender_endpoint.address().to_string()
377 + ":" + std::to_string(state.sender_endpoint.port());
378
379 std::shared_lock lock(m_endpoints_mutex);
380 for (const auto& [id, record] : m_endpoints) {
381 if (record.socket_state->local_port == state.local_port
382 && record.info.role != EndpointRole::SEND) {
383 m_receive_callback(id, state.recv_buffer.data(), bytes_received, sender_str);
384 }
385 }
386 }
387
388 start_receive_loop(state);
389}
#define MF_WARN(comp, ctx,...)
NetworkReceiveCallback m_receive_callback
std::unordered_map< uint64_t, EndpointRecord > m_endpoints
void start_receive_loop(SocketState &state)
Post the first async_receive_from for a newly bound socket.
std::shared_mutex m_endpoints_mutex
@ NetworkBackend
Network transport backend (UDP, TCP, SHM)
@ Core
Core engine, backend, subsystems.

References MayaFlux::Journal::Core, MayaFlux::Core::UDPBackend::SocketState::local_port, m_endpoints, m_endpoints_mutex, m_receive_callback, MF_WARN, MayaFlux::Journal::NetworkBackend, MayaFlux::Core::UDPBackend::SocketState::recv_buffer, MayaFlux::Core::SEND, MayaFlux::Core::UDPBackend::SocketState::sender_endpoint, and start_receive_loop().

+ Here is the call graph for this function: