void AsyncAcceptManaged(ManagerAcceptHandler mgrHandler)
{
_acceptor.async_accept(_socket, [this, mgrHandler](boost::system::error_code error)
{
if (!error)
{
try
{
_socket.non_blocking(true);
mgrHandler(std::move(_socket));
}
catch (boost::system::system_error const& err)
{
TC_LOG_INFO("network", "Failed to initialize client's socket %s", err.what());
}
}
AsyncAcceptManaged(mgrHandler);
});
}
其中:
typedef void(*ManagerAcceptHandler)(tcp::socket&& newSocket);
tcp::acceptor _acceptor;
C++11新特性,lambada,實際上是一個函數對象