Description
void do_accept() {
if (close_request_) return;
acceptor_.async_accept(
socket_->lowest_layer(),
[this]
(boost::system::error_code const& ec) {
if (ec) {
boost::system::error_code close_ec;
acceptor_.close(close_ec);
if (h_error_) h_error_(ec);
return;
}
auto sp = std::make_shared<endpoint_t>(std::move(socket_));
if (h_accept_) h_accept_(*sp);
renew_socket();
do_accept();
}
);
}
In this function, there's a small gap between when an incoming tcp connection is accepted, and the next socket is initialized.
I believe that async_accept is able to handle multiple sockets at once, and only one of them will be selected per incoming tcp connection.
One way to approach supporting multiple simultaneous incoming TCP connections is to have a std::array<std::unique_ptr<socket_t>, N> (where N can be supplied as a template parameter to server, but defaults to some small number, like 5.)
do_accept's current logic gets moved to do_accept_impl(), and do_accept calls do_accept_impl() in a for-loop, once per std::array index.
Then for each call to accept_async, we provide a different index number into the std::array, which is then passed to the subsequent call to do_accept_impl().