c++ – Boost::ASIO resolve muliple addresses
I’m having some problems resolving multiple addresses using Boost::ASIO. I can call async_resolve once, get an endpoint, and connect to it without issues. But if I want to call async_resolve again at a later point, async_resolve hangs forever and never calls my event handler.
Is there a way to finish or close the previous async_resolve? Or is it something else?
hostResolver = new boost::asio::ip::tcp::resolver(*internalEventPump->getIoService());
hostResolver->async_resolve(boost::asio::ip::tcp::v4(), hostName, portString,
boost::bind(&DTcpSocket::resolveFinished, this, boost::asio::placeholders::error, boost::asio::placeholders::iterator));
…
void DTcpSocket::resolveFinished(const boost::system::error_code &errorCode,
boost::asio::ip::tcp::resolver::iterator iterator)
{
endPointIter = iterator;
if (errorCode)
{
errMsg = "Couldn't resolve hostname: " + errorCode.message();
connectionHandler(errMsg, DA_HOSTNAME_ERROR);
}
else
{
boost::asio::ip::tcp::endpoint endpoint = *endPointIter;
cout << endpoint.address() << endl;
endPointIter++;//we'll try to connect to this endpoint if the first endpoint failed.
clientSocket->async_connect(endpoint, boost::bind(&DTcpSocket::connectFinished, this,
boost::asio::placeholders::error));
}
}//resolveFinished
Read more here: Source link
