I have a canning loudspeaker calling boost::asio::ip::tcp::resolver::resolve()on localhostonce every 5 seconds. It counts the number of returned endpoints and compares this value with the previous iteration.
#include <boost/asio.hpp>
#include <iostream>
int main(int argc, char *argv[])
{
if ( argc < 3 ) {
std::cerr << argv[0] << " host port" << std::endl;
exit( EXIT_FAILURE );
}
const char* host = argv[1];
const char* service = argv[2];
boost::asio::io_service io_service;
boost::asio::ip::tcp::resolver resolver( io_service );
size_t previous = 0;
while ( true ) {
boost::asio::ip::tcp::resolver::iterator i(
resolver.resolve(
boost::asio::ip::tcp::resolver::query( host, service )
)
);
size_t count( 0 );
while ( i != boost::asio::ip::tcp::resolver::iterator() ) {
std::cout << i->endpoint() << std::endl;
++i;
++count;
}
std::cout << "got " << count << " addresses" << std::endl;
if ( previous == 0 ) {
previous = count;
}
assert( count == previous );
sleep( 5 );
}
}
trial session
~> time ./addrinfo_asio localhost 80
...
127.0.0.1:80
got 1 addresses
[::1]:80
127.0.0.1:80
got 2 addresses
addrinfo_asio: addrinfo_asio.cc:35: int main(int, char**): Assertion `count == previous' failed.
Aborted (core dumped)
real 216m20.515s
user 0m0.181s
sys 0m0.193s
~>
You can see that he found one endpoint (127.0.0.1:80) for about 3.5 hours, then he found two (127.0.0.1:80 and [:: 1]: 80). I'm interested
- why does the number of endpoints change from one to two?
- what can cause this?
ipv4 ipv6 , ipv4. , , , asio, , getaddrinfo , . - ppc64 RHEL 6.2, . .