From 44bda1fc106d29da3743f5fda038f8cc8d56cbac Mon Sep 17 00:00:00 2001 From: loonycyborg Date: Wed, 24 Feb 2021 14:46:28 +0300 Subject: [PATCH] Reinstate conditional compilation to support pre-boost-1.66 resolver --- src/network_asio.cpp | 12 ++++++++++-- src/wesnothd_connection.cpp | 14 ++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/network_asio.cpp b/src/network_asio.cpp index ff1c3db4b09b..42dc5d70160f 100644 --- a/src/network_asio.cpp +++ b/src/network_asio.cpp @@ -81,14 +81,22 @@ connection::connection(const std::string& host, const std::string& service) , bytes_read_(0) { boost::system::error_code ec; - auto result = resolver_.resolve(host, service, boost::asio::ip::resolver_query_base::numeric_host, ec); +#if BOOST_VERSION >= 106600 +#define CAMPAIGND_HOST_SPECIFICATION host, service +#define CAMPAIGND_HOST_SPECIFICATION_NUMERIC CAMPAIGND_HOST_SPECIFICATION, boost::asio::ip::resolver_query_base::numeric_host +#else +#define CAMPAIGND_HOST_SPECIFICATION boost::asio::ip::tcp::resolver::query(host, service) +#define CAMPAIGND_HOST_SPECIFICATION_NUMERIC boost::asio::ip::tcp::resolver::query(host, service, boost::asio::ip::resolver_query_base::numeric_host) +#endif + auto result = resolver_.resolve(CAMPAIGND_HOST_SPECIFICATION_NUMERIC, ec); if(!ec) { // if numeric resolve succeeds then we got raw ip address so TLS host name validation would never pass use_tls_ = false; boost::asio::post(io_context_, [this, ec, result](){ handle_resolve(ec, { result } ); } ); } else { - resolver_.async_resolve(host, service, + resolver_.async_resolve(CAMPAIGND_HOST_SPECIFICATION, std::bind(&connection::handle_resolve, this, std::placeholders::_1, std::placeholders::_2)); } +#undef CAMPAIGND_HOST_SPECIFICATION LOG_NW << "Resolving hostname: " << host << '\n'; } diff --git a/src/wesnothd_connection.cpp b/src/wesnothd_connection.cpp index 4285520b2f7a..da5224afd1fa 100644 --- a/src/wesnothd_connection.cpp +++ b/src/wesnothd_connection.cpp @@ -80,16 +80,26 @@ wesnothd_connection::wesnothd_connection(const std::string& host, const std::str { MPTEST_LOG; +#if BOOST_VERSION >= 106600 +#define WESNOTHD_HOST_SPECIFICATION host, service +#define WESNOTHD_HOST_SPECIFICATION_NUMERIC WESNOTHD_HOST_SPECIFICATION, boost::asio::ip::resolver_query_base::numeric_host +#else +#define WESNOTHD_HOST_SPECIFICATION boost::asio::ip::tcp::resolver::query(host, service) +#define WESNOTHD_HOST_SPECIFICATION_NUMERIC boost::asio::ip::tcp::resolver::query(host, service, boost::asio::ip::resolver_query_base::numeric_host) +#endif + error_code ec; - auto result = resolver_.resolve(host, service, boost::asio::ip::resolver_query_base::numeric_host, ec); + auto result = resolver_.resolve(WESNOTHD_HOST_SPECIFICATION_NUMERIC, ec); if(!ec) { // if numeric resolve succeeds then we got raw ip address so TLS host name validation would never pass use_tls_ = false; boost::asio::post(io_context_, [this, ec, result](){ handle_resolve(ec, { result } ); } ); } else { - resolver_.async_resolve(host, service, + resolver_.async_resolve(WESNOTHD_HOST_SPECIFICATION, std::bind(&wesnothd_connection::handle_resolve, this, std::placeholders::_1, std::placeholders::_2)); } +#undef WESNOTHD_HOST_SPECIFICATION + // Starts the worker thread. Do this *after* the above async_resolve call or it will just exit immediately! worker_thread_ = std::thread([this]() { try {