Skip to content

Commit

Permalink
use only ipv4 if problem with ipv6
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Bonani <[email protected]>
  • Loading branch information
ypiguet-epfl authored and Michael Bonani committed Nov 25, 2021
1 parent 42b3311 commit 77c67a2
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions aseba/thymio-device-manager/app_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@ template <typename socket_type>
class application_server {
public:
application_server(boost::asio::io_context& io_context, uint16_t port = 0)
: m_io_context(io_context), m_acceptor(io_context, tcp::endpoint(tcp::v6(), port)) {
// Make sure we accept both ipv4 + ipv6
boost::asio::ip::v6_only opt(false);
boost::system::error_code ec;
m_acceptor.set_option(opt, ec);
m_acceptor.listen(boost::asio::socket_base::max_listen_connections);
: m_io_context(io_context), m_acceptor(io_context) {
try {
m_acceptor = tcp::acceptor(io_context, tcp::endpoint(tcp::v6(), port));
// Make sure we accept both ipv4 + ipv6
boost::asio::ip::v6_only opt(false);
boost::system::error_code ec;
m_acceptor.set_option(opt, ec);
} catch (std::exception &e) {
// IPv6 failed: try IPv4
mLogInfo("IPv6 failed, switch to IPv4-only");
m_acceptor = tcp::acceptor(io_context, tcp::endpoint(tcp::v4(), port));
}
m_acceptor.listen(boost::asio::socket_base::max_listen_connections);
}

tcp::acceptor::endpoint_type endpoint() const {
Expand Down

0 comments on commit 77c67a2

Please sign in to comment.