Browse Source

try not to loop over all addresses
we're only using one at this point so restart loop if we found one

Jelte Jansen 14 years ago
parent
commit
848b1823fc
1 changed files with 24 additions and 20 deletions
  1. 24 20
      src/lib/asiolink/udpdns.cc

+ 24 - 20
src/lib/asiolink/udpdns.cc

@@ -308,28 +308,32 @@ UDPQuery::operator()(error_code ec, size_t length) {
                 // this needs to tie into NSAS of course
                 // this needs to tie into NSAS of course
                 // for this very first mockup, hope there is an
                 // for this very first mockup, hope there is an
                 // address in additional and just use that
                 // address in additional and just use that
-                if (incoming.getRRCount(Message::SECTION_ADDITIONAL) > 0) {
-                    // send query to the first address
-                    for (RRsetIterator rrsi = incoming.beginSection(Message::SECTION_ADDITIONAL);
-                         rrsi != incoming.endSection(Message::SECTION_ADDITIONAL);
-                         rrsi++) {
-                        ConstRRsetPtr rrs = *rrsi;
-                        if (rrs->getType() == RRType::A()) {
-                            // found address
-                            RdataIteratorPtr rdi = rrs->getRdataIterator();
-                            // just use the first
-                            if (!rdi->isLast()) {
-                                std::string addr_str = rdi->getCurrent().toText();
-                                dlog("[XX] first address found: " + addr_str);
-                                // now we have one address, simply
-                                // resend that exact same query
-                                // to that address and yield, when it
-                                // returns, loop again.
-                                //ip::address addr = 
-                                data_->remote.address(ip::address::from_string(addr_str));
-                            }
+
+                // send query to the first address
+                bool found_address = false;
+                for (RRsetIterator rrsi = incoming.beginSection(Message::SECTION_ADDITIONAL);
+                     rrsi != incoming.endSection(Message::SECTION_ADDITIONAL) && !found_address;
+                     rrsi++) {
+                    ConstRRsetPtr rrs = *rrsi;
+                    if (rrs->getType() == RRType::A()) {
+                        // found address
+                        RdataIteratorPtr rdi = rrs->getRdataIterator();
+                        // just use the first
+                        if (!rdi->isLast()) {
+                            std::string addr_str = rdi->getCurrent().toText();
+                            dlog("[XX] first address found: " + addr_str);
+                            // now we have one address, simply
+                            // resend that exact same query
+                            // to that address and yield, when it
+                            // returns, loop again.
+                            //ip::address addr = 
+                            data_->remote.address(ip::address::from_string(addr_str));
+                            found_address = true;
                         }
                         }
                     }
                     }
+                }
+                if (found_address) {
+                    // restart loop
                 } else {
                 } else {
                     dlog("[XX] no ready-made addresses in additional. need nsas.");
                     dlog("[XX] no ready-made addresses in additional. need nsas.");
                     // this will result in answering with the delegation. oh well
                     // this will result in answering with the delegation. oh well