Skip to content

Commit

Permalink
Replace deprecated asio::io_service and asio::ip::tcp::resolver::query
Browse files Browse the repository at this point in the history
Boost APIs
  • Loading branch information
offa committed Jan 7, 2025
1 parent 2b8a87c commit 6f8db95
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 19 deletions.
20 changes: 10 additions & 10 deletions src/TCP.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -52,15 +52,15 @@ 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)
{
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");
Expand Down
2 changes: 1 addition & 1 deletion src/TCP.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 8 additions & 5 deletions src/UDP.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/UDP.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/UnixSocket.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/UnixSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6f8db95

Please sign in to comment.