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