MCPcopy Create free account
hub / github.com/COVESA/vsomeip / async_accept

Method async_accept

implementation/endpoints/src/local_acceptor_tcp_impl.cpp:81–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79}
80
81void local_acceptor_tcp_impl::async_accept(connection_handler _handler) {
82 std::scoped_lock const lock{mtx_};
83 // tmp_socket is a `shared_ptr` due to the `std::function` below which requires everything to be copyable
84 std::shared_ptr<tcp_socket> tmp_socket = abstract_socket_factory::get()->create_tcp_socket(io_);
85 // Use the peer-endpoint overload so the remote address is captured by the kernel at accept() time.
86 // If the client disconnects immediately after connecting, calling remote_endpoint() on the socket
87 // in the callback would fail
88 auto tmp_remote_ep = std::make_shared<boost::asio::ip::tcp::endpoint>();
89 acceptor_->async_accept(*tmp_socket, *tmp_remote_ep,
90 [weak_self = weak_from_this(), h = std::move(_handler), tmp_socket, tmp_remote_ep](auto const& _ec) {
91 if (auto self = weak_self.lock(); self) {
92 self->accept_cbk(_ec, std::move(h), tmp_socket, tmp_remote_ep);
93 }
94 });
95}
96
97// NOSONAR(cpp:S5213) - Handler is already std::function from async_accept, making this a template provides no benefit
98void local_acceptor_tcp_impl::accept_cbk(boost::system::error_code const& _ec, connection_handler _handler,

Callers 2

startMethod · 0.45
start_unlockMethod · 0.45

Calls 3

accept_cbkMethod · 0.95
lockMethod · 0.80
create_tcp_socketMethod · 0.45

Tested by

no test coverage detected