Browse Source

don't % 0 if there are no upstreams configured

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac327@3784 e5f2f494-b856-4b98-b285-d166d9295462
Jelte Jansen 14 years ago
parent
commit
c3201cec51
1 changed files with 13 additions and 9 deletions
  1. 13 9
      src/lib/asiolink/asiolink.cc

+ 13 - 9
src/lib/asiolink/asiolink.cc

@@ -144,7 +144,6 @@ public:
                 address, port, checkin_, lookup_, answer_));
             (*tcpServer)();
             servers_.push_back(tcpServer);
-
             UDPServerPtr udpServer(new UDPServer(io_service_.get_io_service(),
                 address, port, checkin_, lookup_, answer_));
             (*udpServer)();
@@ -313,14 +312,19 @@ class RunningQuery : public UDPQuery::Callback {
             unsigned retries_;
             // (re)send the query to the server.
             void send() {
-                int serverIndex(random() % upstream_->size());
-                dlog("Sending upstream query (" + question_.toText() +
-                    ") to " + upstream_->at(serverIndex).first);
-                UDPQuery query(io_, question_,
-                    upstream_->at(serverIndex).first,
-                    upstream_->at(serverIndex).second, buffer_, this,
-                    timeout_);
-                io_.post(query);
+                const int uc = upstream_->size();
+                if (uc > 0) {
+                    int serverIndex(random() % uc);
+                    dlog("Sending upstream query (" + question_.toText() +
+                        ") to " + upstream_->at(serverIndex).first);
+                    UDPQuery query(io_, question_,
+                        upstream_->at(serverIndex).first,
+                        upstream_->at(serverIndex).second, buffer_, this,
+                        timeout_);
+                    io_.post(query);
+                } else {
+                    dlog("Error, no upstream servers to send to.");
+                }
             }
         public:
             RunningQuery(asio::io_service& io, const Question &question,