Skip to content

Commit

Permalink
Reinstate conditional compilation to support pre-boost-1.66 resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
loonycyborg committed Feb 27, 2021
1 parent 09d074f commit 44bda1f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/network_asio.cpp
Expand Up @@ -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';
}
Expand Down
14 changes: 12 additions & 2 deletions src/wesnothd_connection.cpp
Expand Up @@ -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 {
Expand Down

0 comments on commit 44bda1f

Please sign in to comment.