From: Fred Morcos Date: Wed, 15 Feb 2023 15:13:44 +0000 (+0100) Subject: Cleanup Socker::recvFromAsync X-Git-Tag: dnsdist-1.8.0-rc1~3^2~9 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9912fa430b04dbf4264aa4c5513b147a792c6fb1;p=thirdparty%2Fpdns.git Cleanup Socker::recvFromAsync --- diff --git a/pdns/dnsreplay.cc b/pdns/dnsreplay.cc index 2860febfb6..8d3a529b8e 100644 --- a/pdns/dnsreplay.cc +++ b/pdns/dnsreplay.cc @@ -39,17 +39,17 @@ There is one central object, which has (when complete) Original answer Socket answer -What to do with timeouts. We keep around at most 65536 outstanding answers. +What to do with timeouts. We keep around at most 65536 outstanding answers. */ -/* +/* mental_clock=0; for(;;) { do { read a packet send a packet - } while(time_of_last_packet_sent < mental_clock) + } while(time_of_last_packet_sent < mental_clock) mental_clock=time_of_last_packet_sent; wait for a response packet for 0.1 seconds @@ -87,7 +87,7 @@ using namespace ::boost::multi_index; StatBag S; bool g_quiet=true; -int g_timeoutMsec=0; +int g_timeoutMsec=0; namespace po = boost::program_options; @@ -106,9 +106,9 @@ static const struct timeval operator*(float fact, const struct timeval& rhs) ret.tv_usec=(unsigned int)(1000000*d); normalizeTV(ret); - + cout<<"out complex: "< d_available; - + } s_idmanager; struct AssignedIDTag{}; @@ -181,13 +181,13 @@ struct QuestionData }; typedef multi_index_container< - QuestionData, + QuestionData, indexed_by< ordered_unique, BOOST_MULTI_INDEX_MEMBER(QuestionData, QuestionIdentifier, d_qi) > , ordered_unique, BOOST_MULTI_INDEX_MEMBER(QuestionData, int, d_assignedID) > > > qids_t; - + qids_t qids; bool g_throttled; @@ -209,7 +209,7 @@ static void WeOrigSlowQueriesDelta(int& weOutstanding, int& origOutstanding, int for(qids_t::iterator i=qids.begin(); i!=qids.end(); ++i) { double dt=DiffTime(i->d_resentTime, now); if(dt < 2.0) { - if(i->d_newRcode == -1) + if(i->d_newRcode == -1) weOutstanding++; if(i->d_origRcode == -1) origOutstanding++; @@ -273,7 +273,7 @@ vector flightTimes; static void accountFlightTime(qids_t::const_iterator iter) { if(flightTimes.empty()) - flightTimes.resize(2050); + flightTimes.resize(2050); struct timeval now; gettimeofday(&now, 0); @@ -307,12 +307,12 @@ static void emitFlightTimes() for(unsigned int i =0 ; i < sizeof(limits)/sizeof(limits[0]); ++i) { if(limits[i]!=flightTimes.size()) cout<<"Within "< canonicOrig, canonicNew; compactAnswerSet(qd.d_origAnswers, canonicOrig); compactAnswerSet(qd.d_newAnswers, canonicNew); - + if(!g_quiet) { - cout<getHandle(), g_timeoutMsec/1000, 1000*(g_timeoutMsec%1000)); - + if(res < 0 || res==0) return; - while(s_socket->recvFromAsync(packet, remote)) { + while(s_socket->recvFromAsync(packet)) { try { s_weanswers++; MOADNSParser mdp(false, packet.c_str(), packet.length()); @@ -407,13 +407,13 @@ try qids_by_id_index_t& idindex=qids.get(); qids_by_id_index_t::const_iterator found=idindex.find(ntohs(mdp.d_header.id)); if(found == idindex.end()) { - if(!g_quiet) + if(!g_quiet) cout<<"Received an answer ("< 1000) { cerr<<"Too many questions ("<qr) { // this is to stress out the reference server with all the pain s_questions++; qd.d_assignedID = s_idmanager.getID(); @@ -664,12 +664,12 @@ static bool sendPacketFromPR(PcapPacketReader& pr, const ComboAddress& remote, i } else { s_origanswers++; - qids_t::const_iterator iter=qids.find(qi); + qids_t::const_iterator iter=qids.find(qi); if(iter != qids.end()) { QuestionData eqd=*iter; eqd.d_origAnswers=mdp.d_answers; eqd.d_origRcode=mdp.d_header.rcode; - + if(!dh->ra) { s_norecursionavailable++; eqd.d_norecursionavailable=true; @@ -679,7 +679,7 @@ static bool sendPacketFromPR(PcapPacketReader& pr, const ComboAddress& remote, i if(eqd.d_newRcode!=-1) { measureResultAndClean(iter); } - + return sent; } else { @@ -702,7 +702,7 @@ static bool sendPacketFromPR(PcapPacketReader& pr, const ComboAddress& remote, i } s_idmanager.releaseID(qd.d_assignedID); // not added to qids for cleanup - s_origdnserrors++; + s_origdnserrors++; } return sent; @@ -799,7 +799,7 @@ try cerr<(), + ComboAddress remote(g_vm["target-ip"].as(), g_vm["target-port"].as()); int stamp = -1; @@ -827,12 +827,12 @@ try cerr<<"Interrupted from terminal"<= packetLimit) + } + if(packetLimit && count >= packetLimit) break; mental_time=packet_ts; @@ -869,4 +869,3 @@ catch(std::exception& e) { cerr<<"Fatal: "<(bytes)); } - bool recvFromAsync(string &dgram, ComboAddress& /* ep */) + bool recvFromAsync(string &dgram) { struct sockaddr_in remote; socklen_t remlen = sizeof(remote);