Initiate async_accept loop for a listener.
399{
400 listener.pending_socket = asio::ip::tcp::socket(
m_context);
401
402 listener.acceptor.async_accept(
403 listener.pending_socket,
404 [this, listener_id = listener.info.id](const asio::error_code& ec) {
405 std::shared_lock lock(m_listeners_mutex);
406 auto it = m_listeners.find(listener_id);
407 if (it == m_listeners.end()) {
408 return;
409 }
410
411 auto& lst = *it->second;
412
413 if (ec) {
414 if (ec == asio::error::operation_aborted) {
415 return;
416 }
418 "TCP accept error on listener {}: {}", listener_id, ec.message());
420 return;
421 }
422
423 uint64_t new_id = 0;
426 }
427
428 auto peer_ep = lst.pending_socket.remote_endpoint();
429 std::string peer_addr = peer_ep.address().to_string();
430 uint16_t peer_port = peer_ep.port();
431
432 auto conn = std::make_unique<ConnectionState>(
m_context);
433 conn->socket = std::move(lst.pending_socket);
434 conn->is_outbound = false;
435 conn->info.id = new_id;
439 conn->info.remote_address = peer_addr;
440 conn->info.remote_port = peer_port;
441 conn->info.local_port = lst.info.local_port;
442
443 auto* raw = conn.get();
444
445 {
448 }
449
452 }
453
455
457 "TCP accepted connection {} from {}:{} on listener {}",
458 new_id, peer_addr, peer_port, listener_id);
459
461 });
462}
#define MF_INFO(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
void start_receive_chain(ConnectionState &conn)
Start the framed message receive chain on a connection.
std::function< uint64_t()> m_allocate_endpoint_id
Pointer to subsystem's endpoint id allocator.
std::unordered_map< uint64_t, std::unique_ptr< ConnectionState > > m_connections
void start_accept(ListenerState &listener)
Initiate async_accept loop for a listener.
std::shared_mutex m_connections_mutex
asio::io_context & m_context
EndpointStateCallback m_state_callback
@ NetworkBackend
Network transport backend (UDP, TCP, SHM)
@ Core
Core engine, backend, subsystems.