Send data through an endpoint.
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.
287{
291 return false;
292 }
293
294 auto& conn = *it->second;
296 return false;
297 }
298
299 auto frame = std::make_shared<std::vector<uint8_t>>(
sizeof(uint32_t) +
size);
300 uint32_t net_len = htonl(
static_cast<uint32_t
>(
size));
301 std::memcpy(frame->data(), &net_len, sizeof(uint32_t));
302 std::memcpy(frame->data() +
sizeof(uint32_t), data,
size);
303
304 asio::async_write(
305 conn.socket,
306 asio::buffer(*frame),
307 [frame, endpoint_id, this](const asio::error_code& ec, size_t) {
308 if (ec) {
309 MF_WARN(Journal::Component::Core, Journal::Context::NetworkBackend,
310 "TCP write failed on endpoint {}: {}", endpoint_id, ec.message());
311
312 std::shared_lock lk(m_connections_mutex);
313 auto cit = m_connections.find(endpoint_id);
314 if (cit != m_connections.end()) {
315 on_connection_error(*cit->second, ec);
316 }
317 }
318 });
319
320 return true;
321}
std::unordered_map< uint64_t, std::unique_ptr< ConnectionState > > m_connections
std::shared_mutex m_connections_mutex