|
Boost : |
From: Tarun Batra (tbatra18_at_[hidden])
Date: 2023-05-08 08:29:35
Hi,
I am doing a homegrown project, which i am adding support to ipv6 where i 2
different codes:
*First code:*
my_Acceptor = new tcp::acceptor(myService,
tcp::endpoint(boost::asio::ip::address_v4::loopback(),port));
*Second code:*
my_acceptor = new tcp::acceptor(myContext, tcp::endpoint(ifallowed ?
boost::asio::ip::address_v4::any() :
boost::asio::ip::address_v4::loopback(),port));
What I wanted to ask is, is there any way in boost by which we can first
try things on ipv6 and if that doesn't work fall to ipv4.
*Since it is just loopback address, is it a better way than this, for the
first code*
try{
my_Acceptor = new tcp::acceptor(myService,
tcp::endpoint(boost::asio::ip::address_v6::loopback(),port));
}
catch(boost::system::system_error& e)
{
printf("Error Starting on v6, trying on v4: %s\n", e.what());
}
try{
my_Acceptor = new tcp::acceptor(myService,
tcp::endpoint(boost::asio::ip::address_v4::loopback(),port));
}
catch(boost::system::system_error& e)
{
printf("Error Starting on v4,: %s\n", e.what());
return;
}
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk