From 6f8db9522d71409e080726aff7873d10ad68b44f Mon Sep 17 00:00:00 2001 From: offa Date: Tue, 7 Jan 2025 18:47:58 +0100 Subject: [PATCH] Replace deprecated asio::io_service and asio::ip::tcp::resolver::query Boost APIs --- src/TCP.cxx | 20 ++++++++++---------- src/TCP.h | 2 +- src/UDP.cxx | 13 ++++++++----- src/UDP.h | 2 +- src/UnixSocket.cxx | 2 +- src/UnixSocket.h | 2 +- 6 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/TCP.cxx b/src/TCP.cxx index 2ebb41a..a72290a 100644 --- a/src/TCP.cxx +++ b/src/TCP.cxx @@ -30,16 +30,16 @@ namespace influxdb::transports { - namespace ba = boost::asio; - TCP::TCP(const std::string& hostname, int port) - : mSocket(mIoService) + : mSocket(mIoContext) { - ba::ip::tcp::resolver resolver(mIoService); - ba::ip::tcp::resolver::query query(hostname, std::to_string(port)); - ba::ip::tcp::resolver::iterator resolverIterator = resolver.resolve(query); - ba::ip::tcp::resolver::iterator end; - mEndpoint = *resolverIterator; + boost::asio::ip::tcp::resolver resolver(mIoContext); + mEndpoint = *(resolver + .resolve(boost::asio::ip::tcp::v4(), + hostname, + std::to_string(port), + boost::asio::ip::resolver_query_base::passive) + .cbegin()); mSocket.open(mEndpoint.protocol()); reconnect(); } @@ -52,7 +52,7 @@ namespace influxdb::transports void TCP::reconnect() { mSocket.connect(mEndpoint); - mSocket.wait(ba::ip::tcp::socket::wait_write); + mSocket.wait(boost::asio::ip::tcp::socket::wait_write); } void TCP::send(std::string&& message) @@ -60,7 +60,7 @@ namespace influxdb::transports try { message.append("\n"); - const size_t written = mSocket.write_some(ba::buffer(message, message.size())); + const size_t written = mSocket.write_some(boost::asio::buffer(message, message.size())); if (written != message.size()) { throw InfluxDBException("Error while transmitting data"); diff --git a/src/TCP.h b/src/TCP.h index e1e92e3..b3e1a32 100644 --- a/src/TCP.h +++ b/src/TCP.h @@ -54,7 +54,7 @@ namespace influxdb::transports private: /// Boost Asio I/O functionality - boost::asio::io_service mIoService; + boost::asio::io_context mIoContext; /// TCP socket boost::asio::ip::tcp::socket mSocket; diff --git a/src/UDP.cxx b/src/UDP.cxx index 800d105..718d039 100644 --- a/src/UDP.cxx +++ b/src/UDP.cxx @@ -33,12 +33,15 @@ namespace influxdb::transports { UDP::UDP(const std::string& hostname, int port) - : mSocket(mIoService, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), 0)) + : mSocket(mIoContext, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), 0)) { - boost::asio::ip::udp::resolver resolver(mIoService); - boost::asio::ip::udp::resolver::query query(boost::asio::ip::udp::v4(), hostname, std::to_string(port)); - boost::asio::ip::udp::resolver::iterator resolverInerator = resolver.resolve(query); - mEndpoint = *resolverInerator; + boost::asio::ip::udp::resolver resolver(mIoContext); + mEndpoint = *(resolver + .resolve(boost::asio::ip::udp::v4(), + hostname, + std::to_string(port), + boost::asio::ip::resolver_query_base::passive) + .cbegin()); } void UDP::send(std::string&& message) diff --git a/src/UDP.h b/src/UDP.h index e8f3a95..c4692a0 100644 --- a/src/UDP.h +++ b/src/UDP.h @@ -49,7 +49,7 @@ namespace influxdb::transports private: /// Boost Asio I/O functionality - boost::asio::io_service mIoService; + boost::asio::io_context mIoContext; /// UDP socket boost::asio::ip::udp::socket mSocket; diff --git a/src/UnixSocket.cxx b/src/UnixSocket.cxx index f6e8f50..05dc7b6 100644 --- a/src/UnixSocket.cxx +++ b/src/UnixSocket.cxx @@ -34,7 +34,7 @@ namespace influxdb::transports #if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) UnixSocket::UnixSocket(const std::string& socketPath) - : mSocket(mIoService), mEndpoint(socketPath) + : mSocket(mIoContext), mEndpoint(socketPath) { mSocket.open(); } diff --git a/src/UnixSocket.h b/src/UnixSocket.h index db21540..7b5a068 100644 --- a/src/UnixSocket.h +++ b/src/UnixSocket.h @@ -47,7 +47,7 @@ namespace influxdb::transports private: /// Boost Asio I/O functionality - boost::asio::io_service mIoService; + boost::asio::io_context mIoContext; #if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) /// Unix socket boost::asio::local::datagram_protocol::socket mSocket;