From: Remi Gacogne Date: Thu, 2 Aug 2018 14:52:28 +0000 (+0200) Subject: rec: Remove a useless copy in arecvfrom(), reserve whenever possible X-Git-Tag: dnsdist-1.3.3~169^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f128d20dc793091cdd92192380bb238722430e78;p=thirdparty%2Fpdns.git rec: Remove a useless copy in arecvfrom(), reserve whenever possible --- diff --git a/pdns/lwres.cc b/pdns/lwres.cc index 4739ae10a3..ba0c3322a6 100644 --- a/pdns/lwres.cc +++ b/pdns/lwres.cc @@ -170,7 +170,7 @@ int asyncresolve(const ComboAddress& ip, const DNSName& domain, int type, bool d // sleep until we see an answer to this, interface to mtasker - ret=arecvfrom(const_cast(buf.data()), buf.size(), 0, ip, &len, qid, + ret=arecvfrom(buf, 0, ip, &len, qid, domain, type, queryfd, now); } else { @@ -248,7 +248,8 @@ int asyncresolve(const ComboAddress& ip, const DNSName& domain, int type, bool d // unexpected count has already been done @ pdns_recursor.cc goto out; } - + + lwr->d_records.reserve(mdp.d_answers.size()); for(const auto& a : mdp.d_answers) lwr->d_records.push_back(a.first); diff --git a/pdns/lwres.hh b/pdns/lwres.hh index 98c3f0845d..1397812627 100644 --- a/pdns/lwres.hh +++ b/pdns/lwres.hh @@ -45,7 +45,7 @@ int asendto(const char *data, size_t len, int flags, const ComboAddress& ip, uint16_t id, const DNSName& domain, uint16_t qtype, int* fd); -int arecvfrom(char *data, size_t len, int flags, const ComboAddress& ip, size_t *d_len, uint16_t id, +int arecvfrom(std::string& packet, int flags, const ComboAddress& ip, size_t *d_len, uint16_t id, const DNSName& domain, uint16_t qtype, int fd, struct timeval* now); class LWResException : public PDNSException diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 4901ca45b8..d854a7f0ee 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -659,7 +659,7 @@ int asendto(const char *data, size_t len, int flags, } // -1 is error, 0 is timeout, 1 is success -int arecvfrom(char *data, size_t len, int flags, const ComboAddress& fromaddr, size_t *d_len, +int arecvfrom(std::string& packet, int flags, const ComboAddress& fromaddr, size_t *d_len, uint16_t id, const DNSName& domain, uint16_t qtype, int fd, struct timeval* now) { static optional nearMissLimit; @@ -673,7 +673,6 @@ int arecvfrom(char *data, size_t len, int flags, const ComboAddress& fromaddr, s pident.type = qtype; pident.remote=fromaddr; - string packet; int ret=MT->waitEvent(pident, &packet, g_networkTimeoutMsec, now); if(ret > 0) { @@ -681,7 +680,7 @@ int arecvfrom(char *data, size_t len, int flags, const ComboAddress& fromaddr, s return -1; *d_len=packet.size(); - memcpy(data,packet.c_str(),min(len,*d_len)); + if(*nearMissLimit && pident.nearMisses > *nearMissLimit) { g_log< "<<*nearMissLimit<<") bogus answers for '"<