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

◆ send_to()

bool MayaFlux::Core::UDPBackend::send_to ( uint64_t  endpoint_id,
const uint8_t *  data,
size_t  size,
const std::string &  address,
uint16_t  port 
)
overridevirtual

Send data to a specific address through an endpoint.

Parameters
endpoint_idSource endpoint (must be open).
dataPointer to payload bytes.
sizePayload size in bytes.
addressTarget address string.
portTarget port.
Returns
true if the send was accepted.

Primary use: UDP (send to arbitrary peer via bound socket). TCP: ignored, uses connected peer. SHM: ignored.

Implements MayaFlux::Core::INetworkBackend.

Definition at line 217 of file UDPBackend.cpp.

219{
220 std::shared_lock lock(m_endpoints_mutex);
221 auto it = m_endpoints.find(endpoint_id);
222 if (it == m_endpoints.end()) {
223 return false;
224 }
225
226 asio::error_code ec;
227 auto addr = asio::ip::make_address(address, ec);
228 if (ec) {
230 "Invalid send_to address '{}': {}", address, ec.message());
231 return false;
232 }
233
234 asio::ip::udp::endpoint target(addr, port);
235 auto buf = std::make_shared<std::vector<uint8_t>>(data, data + size);
236 auto& socket = it->second.socket_state->socket;
237
238 socket.async_send_to(
239 asio::buffer(*buf), target,
240 [buf, endpoint_id](const asio::error_code& send_ec, size_t) {
241 if (send_ec) {
243 "UDP send_to failed on endpoint {}: {}", endpoint_id, send_ec.message());
244 }
245 });
246
247 return true;
248}
#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.