From d651ad51deb62c53cc6bc417d0d861d7124f5aae Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Tue, 4 Jan 2022 11:22:27 +0100 Subject: [PATCH] Stop using the deprecated boost::shared_array It was deprecated in 1.65.0: `This facility is deprecated because a shared_ptr to T[] or T[N] is now available, and is superior in every regard`. As far as I can tell we never actually used the reference counting 'shared' feature anyway. --- pdns/axfr-retriever.cc | 12 ++++++------ pdns/axfr-retriever.hh | 3 +-- pdns/epollmplexer.cc | 8 ++++---- pdns/kqueuemplexer.cc | 8 ++++---- pdns/mplexer.hh | 1 - pdns/pdns_recursor.cc | 1 - pdns/portsmplexer.cc | 8 ++++---- 7 files changed, 19 insertions(+), 22 deletions(-) diff --git a/pdns/axfr-retriever.cc b/pdns/axfr-retriever.cc index 99f386bc14..c206306eeb 100644 --- a/pdns/axfr-retriever.cc +++ b/pdns/axfr-retriever.cc @@ -35,7 +35,7 @@ AXFRRetriever::AXFRRetriever(const ComboAddress& remote, const ComboAddress* laddr, size_t maxReceivedBytes, uint16_t timeout) - : d_tsigVerifier(tt, remote, d_trc), d_receivedBytes(0), d_maxReceivedBytes(maxReceivedBytes) + : d_buf(65536), d_tsigVerifier(tt, remote, d_trc), d_receivedBytes(0), d_maxReceivedBytes(maxReceivedBytes) { ComboAddress local; if (laddr != nullptr) { @@ -51,7 +51,7 @@ AXFRRetriever::AXFRRetriever(const ComboAddress& remote, d_sock = makeQuerySocket(local, false); // make a TCP socket if (d_sock < 0) throw ResolverException("Error creating socket for AXFR request to "+d_remote.toStringWithPort()); - d_buf = boost::shared_array(new char[65536]); + d_remote = remote; // mostly for error reporting this->connect(timeout); d_soacount = 0; @@ -125,7 +125,7 @@ int AXFRRetriever::getChunk(Resolver::res_t &res, vector* records, ui d_receivedBytes += (uint16_t) len; - MOADNSParser mdp(false, d_buf.get(), len); + MOADNSParser mdp(false, d_buf.data(), len); int err = mdp.d_header.rcode; @@ -134,7 +134,7 @@ int AXFRRetriever::getChunk(Resolver::res_t &res, vector* records, ui } try { - d_tsigVerifier.check(std::string(d_buf.get(), len), mdp); + d_tsigVerifier.check(std::string(d_buf.data(), len), mdp); } catch(const std::runtime_error& re) { throw ResolverException(re.what()); @@ -177,7 +177,7 @@ void AXFRRetriever::timeoutReadn(uint16_t bytes, uint16_t timeoutsec) if(!res) throw ResolverException("Timeout while reading data from remote nameserver over TCP"); - numread=recv(d_sock, d_buf.get()+n, bytes-n, 0); + numread=recv(d_sock, &d_buf.at(n), bytes-n, 0); if(numread<0) throw ResolverException("Reading data from remote nameserver over TCP: "+stringerror()); if(numread==0) @@ -243,6 +243,6 @@ void AXFRRetriever::connect(uint16_t timeout) int AXFRRetriever::getLength(uint16_t timeout) { timeoutReadn(2, timeout); - return (unsigned char)d_buf[0]*256+(unsigned char)d_buf[1]; + return (unsigned char)d_buf.at(0)*256+(unsigned char)d_buf.at(1); } diff --git a/pdns/axfr-retriever.hh b/pdns/axfr-retriever.hh index f3e5c2bb88..81362b754b 100644 --- a/pdns/axfr-retriever.hh +++ b/pdns/axfr-retriever.hh @@ -21,7 +21,6 @@ */ #pragma once #include -#include #include "iputils.hh" #include "dnsname.hh" @@ -44,7 +43,7 @@ class AXFRRetriever : public boost::noncopyable int getLength(uint16_t timeout); void timeoutReadn(uint16_t bytes, uint16_t timeoutsec=10); - boost::shared_array d_buf; + std::vector d_buf; string d_domain; int d_sock; int d_soacount; diff --git a/pdns/epollmplexer.cc b/pdns/epollmplexer.cc index d0cbf54885..85158d246f 100644 --- a/pdns/epollmplexer.cc +++ b/pdns/epollmplexer.cc @@ -58,7 +58,7 @@ public: private: int d_epollfd; - boost::shared_array d_eevents; + std::vector d_eevents; static int s_maxevents; // not a hard maximum }; @@ -78,7 +78,7 @@ static struct EpollRegisterOurselves int EpollFDMultiplexer::s_maxevents = 1024; EpollFDMultiplexer::EpollFDMultiplexer() : - d_eevents(new epoll_event[s_maxevents]) + d_eevents(s_maxevents) { d_epollfd = epoll_create(s_maxevents); // not hard max if (d_epollfd < 0) { @@ -156,7 +156,7 @@ void EpollFDMultiplexer::alterFD(int fd, FDMultiplexer::EventKind, FDMultiplexer void EpollFDMultiplexer::getAvailableFDs(std::vector& fds, int timeout) { - int ret = epoll_wait(d_epollfd, d_eevents.get(), s_maxevents, timeout); + int ret = epoll_wait(d_epollfd, d_eevents.data(), s_maxevents, timeout); if (ret < 0 && errno != EINTR) { throw FDMultiplexerException("epoll returned error: " + stringerror()); @@ -173,7 +173,7 @@ int EpollFDMultiplexer::run(struct timeval* now, int timeout) throw FDMultiplexerException("FDMultiplexer::run() is not reentrant!\n"); } - int ret = epoll_wait(d_epollfd, d_eevents.get(), s_maxevents, timeout); + int ret = epoll_wait(d_epollfd, d_eevents.data(), s_maxevents, timeout); gettimeofday(now, nullptr); // MANDATORY if (ret < 0 && errno != EINTR) { diff --git a/pdns/kqueuemplexer.cc b/pdns/kqueuemplexer.cc index a81487c090..f777b80808 100644 --- a/pdns/kqueuemplexer.cc +++ b/pdns/kqueuemplexer.cc @@ -59,7 +59,7 @@ public: private: int d_kqueuefd; - boost::shared_array d_kevents; + std::vector d_kevents; static unsigned int s_maxevents; // not a hard maximum }; @@ -79,7 +79,7 @@ static struct KqueueRegisterOurselves } kQueueDoIt; KqueueFDMultiplexer::KqueueFDMultiplexer() : - d_kevents(new struct kevent[s_maxevents]) + d_kevents(s_maxevents) { d_kqueuefd = kqueue(); if (d_kqueuefd < 0) { @@ -148,7 +148,7 @@ void KqueueFDMultiplexer::getAvailableFDs(std::vector& fds, int timeout) ts.tv_sec = timeout / 1000; ts.tv_nsec = (timeout % 1000) * 1000000; - int ret = kevent(d_kqueuefd, 0, 0, d_kevents.get(), s_maxevents, &ts); + int ret = kevent(d_kqueuefd, 0, 0, d_kevents.data(), s_maxevents, &ts); if (ret < 0 && errno != EINTR) { throw FDMultiplexerException("kqueue returned error: " + stringerror()); @@ -177,7 +177,7 @@ int KqueueFDMultiplexer::run(struct timeval* now, int timeout) ts.tv_sec = timeout / 1000; ts.tv_nsec = (timeout % 1000) * 1000000; - int ret = kevent(d_kqueuefd, 0, 0, d_kevents.get(), s_maxevents, &ts); + int ret = kevent(d_kqueuefd, 0, 0, d_kevents.data(), s_maxevents, &ts); gettimeofday(now, nullptr); // MANDATORY! if (ret < 0 && errno != EINTR) { diff --git a/pdns/mplexer.hh b/pdns/mplexer.hh index d85efe91fe..474ea89067 100644 --- a/pdns/mplexer.hh +++ b/pdns/mplexer.hh @@ -22,7 +22,6 @@ #pragma once #include #include -#include #include #include #include diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index c22e43419b..a021544453 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -61,7 +61,6 @@ #include #include #include -#include #include #include #ifdef MALLOC_TRACE diff --git a/pdns/portsmplexer.cc b/pdns/portsmplexer.cc index d4f36591b1..f5e151043c 100644 --- a/pdns/portsmplexer.cc +++ b/pdns/portsmplexer.cc @@ -36,7 +36,7 @@ public: private: int d_portfd; - boost::shared_array d_pevents; + std::vector d_pevents; static int s_maxevents; // not a hard maximum }; @@ -56,7 +56,7 @@ static struct PortsRegisterOurselves int PortsFDMultiplexer::s_maxevents = 1024; PortsFDMultiplexer::PortsFDMultiplexer() : - d_pevents(new port_event_t[s_maxevents]) + d_pevents(s_maxevents) { d_portfd = port_create(); // not hard max if (d_portfd < 0) { @@ -97,7 +97,7 @@ void PortsFDMultiplexer::getAvailableFDs(std::vector& fds, int timeout) timeoutspec.tv_sec = timeout / 1000; timeoutspec.tv_nsec = (timeout % 1000) * 1000000; unsigned int numevents = 1; - int ret = port_getn(d_portfd, d_pevents.get(), min(PORT_MAX_LIST, s_maxevents), &numevents, &timeoutspec); + int ret = port_getn(d_portfd, d_pevents.data(), min(PORT_MAX_LIST, s_maxevents), &numevents, &timeoutspec); /* port_getn has an unusual API - (ret == -1, errno == ETIME) can mean partial success; you must check (*numevents) in this case @@ -158,7 +158,7 @@ int PortsFDMultiplexer::run(struct timeval* now, int timeout) timeoutspec.tv_sec = timeout / 1000; timeoutspec.tv_nsec = (timeout % 1000) * 1000000; unsigned int numevents = 1; - int ret = port_getn(d_portfd, d_pevents.get(), min(PORT_MAX_LIST, s_maxevents), &numevents, &timeoutspec); + int ret = port_getn(d_portfd, d_pevents.data(), min(PORT_MAX_LIST, s_maxevents), &numevents, &timeoutspec); /* port_getn has an unusual API - (ret == -1, errno == ETIME) can mean partial success; you must check (*numevents) in this case -- 2.47.2