Skip to content

Commit

Permalink
Drop compatibility for boost 1.65
Browse files Browse the repository at this point in the history
  • Loading branch information
loonycyborg committed May 6, 2021
1 parent aad7e14 commit 1c4c5d4
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 69 deletions.
8 changes: 1 addition & 7 deletions CMakeLists.txt
Expand Up @@ -54,13 +54,7 @@ option(ENABLE_TESTS "Build unit tests")
option(ENABLE_NLS "Enable building of translations" ${ENABLE_GAME})
option(ENABLE_HISTORY "Enable using GNU history for history in lua console" ON)

# boost::asio::post is new with 1.66
# Ubuntu 18.04 also only has 1.65
if(ENABLE_MYSQL)
set(BOOST_VERSION "1.66")
else()
set(BOOST_VERSION "1.65")
endif(ENABLE_MYSQL)
set(BOOST_VERSION "1.66")

# set what std version to use
if(NOT CXX_STD)
Expand Down
8 changes: 1 addition & 7 deletions SConstruct
Expand Up @@ -183,13 +183,7 @@ if env['distcc']:

if env['ccache']: env.Tool('ccache')

# boost::asio::post is new with 1.66
# Ubuntu 18.04 also only has 1.65
if env["forum_user_handler"]:
boost_version = "1.66"
else:
boost_version = "1.65"

boost_version = "1.66"

def SortHelpText(a, b):
return (a > b) - (a < b)
Expand Down
13 changes: 1 addition & 12 deletions src/network_asio.cpp
Expand Up @@ -43,11 +43,7 @@ std::deque<boost::asio::const_buffer> split_buffer(boost::asio::streambuf::const
std::deque<boost::asio::const_buffer> buffers;
unsigned int remaining_size = boost::asio::buffer_size(source_buffer);

#if BOOST_VERSION >= 106600
const uint8_t* data = static_cast<const uint8_t*>(source_buffer.data());
#else
const uint8_t* data = boost::asio::buffer_cast<const uint8_t*>(source_buffer);
#endif

while(remaining_size > 0u) {
unsigned int size = std::min(remaining_size, chunk_size);
Expand Down Expand Up @@ -109,11 +105,8 @@ void connection::handle_connect(const boost::system::error_code& ec, endpoint en
ERR_NW << "Tried all IPs. Giving up" << std::endl;
throw system_error(ec);
} else {
#if BOOST_VERSION >= 106600
LOG_NW << "Connected to " << endpoint.address() << '\n';
#else
LOG_NW << "Connected to " << endpoint->endpoint().address() << '\n';
#endif

if(endpoint.address().is_loopback()) {
use_tls_ = false;
}
Expand Down Expand Up @@ -204,11 +197,7 @@ void connection::fallback_to_unencrypted()

void connection::transfer(const config& request, config& response)
{
#if BOOST_VERSION >= 106600
io_context_.restart();
#else
io_context_.reset();
#endif
done_ = false;

write_buf_.reset(new boost::asio::streambuf);
Expand Down
13 changes: 0 additions & 13 deletions src/network_asio.hpp
Expand Up @@ -33,11 +33,7 @@
#include "exceptions.hpp"
#include "utils/variant.hpp"

#if BOOST_VERSION >= 106600
#include <boost/asio/io_context.hpp>
#else
#include <boost/asio/io_service.hpp>
#endif
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/streambuf.hpp>
#include <boost/asio/ssl.hpp>
Expand Down Expand Up @@ -126,11 +122,7 @@ class connection
}

private:
#if BOOST_VERSION >= 106600
boost::asio::io_context io_context_;
#else
boost::asio::io_service io_context_;
#endif

std::string host_;
const std::string service_;
Expand All @@ -150,13 +142,8 @@ class connection
std::unique_ptr<boost::asio::streambuf> write_buf_;
std::unique_ptr<boost::asio::streambuf> read_buf_;

#if BOOST_VERSION >= 106600
using results_type = resolver::results_type;
using endpoint = const boost::asio::ip::tcp::endpoint&;
#else
using results_type = resolver::iterator;
using endpoint = resolver::iterator;
#endif

void handle_resolve(const boost::system::error_code& ec, results_type results);
void handle_connect(const boost::system::error_code& ec, endpoint endpoint);
Expand Down
15 changes: 2 additions & 13 deletions src/wesnothd_connection.cpp
Expand Up @@ -148,11 +148,8 @@ void wesnothd_connection::handle_connect(const boost::system::error_code& ec, en
ERR_NW << "Tried all IPs. Giving up" << std::endl;
throw system_error(ec);
} else {
#if BOOST_VERSION >= 106600
LOG_NW << "Connected to " << endpoint.address() << '\n';
#else
LOG_NW << "Connected to " << endpoint->endpoint().address() << '\n';
#endif

if(endpoint.address().is_loopback()) {
use_tls_ = false;
}
Expand Down Expand Up @@ -272,21 +269,13 @@ void wesnothd_connection::send_data(const configr_of& request)
{
MPTEST_LOG;

#if BOOST_VERSION >= 106600
auto buf_ptr = std::make_unique<boost::asio::streambuf>();
#else
auto buf_ptr = std::make_shared<boost::asio::streambuf>();
#endif

std::ostream os(buf_ptr.get());
write_gz(os, request);

// No idea why io_context::post doesn't like this lambda while asio::post does.
#if BOOST_VERSION >= 106600
boost::asio::post(io_context_, [this, buf_ptr = std::move(buf_ptr)]() mutable {
#else
io_context_.post([this, buf_ptr]() {
#endif

DBG_NW << "In wesnothd_connection::send_data::lambda\n";
send_queue_.push(std::move(buf_ptr));

Expand Down
17 changes: 0 additions & 17 deletions src/wesnothd_connection.hpp
Expand Up @@ -33,11 +33,7 @@
#include "configr_assign.hpp"
#include "wesnothd_connection_error.hpp"

#if BOOST_VERSION >= 106600
#include <boost/asio/io_context.hpp>
#else
#include <boost/asio/io_service.hpp>
#endif
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/streambuf.hpp>
#include <boost/asio/ssl.hpp>
Expand Down Expand Up @@ -139,11 +135,7 @@ class wesnothd_connection
private:
std::thread worker_thread_;

#if BOOST_VERSION >= 106600
boost::asio::io_context io_context_;
#else
boost::asio::io_service io_context_;
#endif

typedef boost::asio::ip::tcp::resolver resolver;
resolver resolver_;
Expand All @@ -166,13 +158,8 @@ class wesnothd_connection

boost::asio::streambuf read_buf_;

#if BOOST_VERSION >= 106600
using results_type = resolver::results_type;
using endpoint = const boost::asio::ip::tcp::endpoint&;
#else
using results_type = resolver::iterator;
using endpoint = resolver::iterator;
#endif

void handle_resolve(const boost::system::error_code& ec, results_type results);
void handle_connect(const boost::system::error_code& ec, endpoint endpoint);
Expand All @@ -196,11 +183,7 @@ class wesnothd_connection
template<typename T>
using data_queue = std::queue<T, std::list<T>>;

#if BOOST_VERSION >= 106600
data_queue<std::unique_ptr<boost::asio::streambuf>> send_queue_;
#else
data_queue<std::shared_ptr<boost::asio::streambuf>> send_queue_;
#endif
data_queue<config> recv_queue_;

std::mutex recv_queue_mutex_;
Expand Down

0 comments on commit 1c4c5d4

Please sign in to comment.