[asio-users] Should async_accept be retried on failure?
Brought to you by:
chris_kohlhoff
From: John S. <js...@gm...> - 2020-05-10 21:40:03
|
Take the following code snippet: void Acceptor::StartNextAccept() { // _acceptor is of type: std::shared_ptr<boost::asio::ip::tcp::acceptor> _acceptor; _acceptor->async_accept([this](const boost::system::error_code& ec, net::ip::tcp::socket sock) { if (ec) { LogErrorCode(ec); // log on failure } else { _callback(sock); // pass socket on to the next component StartNextAccept(); // enqueue next accept } }); } In the fail case, the code just logs that an error happened and stops posting new async_accept calls. The socket effectively stops processing new connections. Are there classes of errors for async_accept, outside of the listen socket being {misconfigured, bad, closed, cancelled}, such that retrying the async_accept call would make sense? Or would that just be an infinite loop of errors? Or put another way, can accept calls fail transiently? If so, what error codes to pay attention to? Thanks, jrs |