]> granicus.if.org Git - pdns/commitdiff
fix timeouts of running TCP client queries - we shouldn't time them out while we...
authorBert Hubert <bert.hubert@netherlabs.nl>
Tue, 18 Apr 2006 12:18:02 +0000 (12:18 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Tue, 18 Apr 2006 12:18:02 +0000 (12:18 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@722 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/mplexer.hh
pdns/pdns_recursor.cc

index 62950448c1c8cc4866b21b029ead1ef1783affa3..ce69b9e0a3b95abdbf132dac5b8241f2b06d9673 100644 (file)
@@ -77,6 +77,13 @@ public:
     d_readCallbacks[fd].d_ttd=tv;
   }
 
+  virtual boost::any& getReadParameter(int fd) 
+  {
+    if(!d_readCallbacks.count(fd))
+      throw FDMultiplexerException("attempt to look up data in multiplexer for unlisted fd "+boost::lexical_cast<std::string>(fd));
+    return d_readCallbacks[fd].d_parameter;
+  }
+
   virtual std::vector<std::pair<int, boost::any> > getTimeouts(const struct timeval& tv)
   {
     std::vector<std::pair<int, boost::any> > ret;
@@ -97,6 +104,7 @@ public:
   
   virtual std::string getName() = 0;
 
+
 protected:
   typedef std::map<int, Callback> callbackmap_t;
   callbackmap_t d_readCallbacks, d_writeCallbacks;
index 087c9ad8b9d3df86e3f7e9f0584ce249a182dd64..2ebfe5a6c07598bf6e6f960cbfbc70c688b9f643 100644 (file)
@@ -525,26 +525,13 @@ void startDoResolve(void *p)
       if(hadError) {
        g_fdm->removeReadFD(dc->d_socket);
        close(dc->d_socket);
-       // i->closeAndCleanup(); // XXX we don't remove ourselves from the list anymore 
       }
-      else 
-       ; // XXX FIXME, need to restore resetting connection to BYTE0 in case of noerror!
-
-#if 0
-      for(vector<TCPConnection>::iterator i=g_tcpconnections.begin();i!=g_tcpconnections.end();++i) {
-       if(i->fd == dc->d_socket) {
-         if(hadError) {
-           i->closeAndCleanup();
-           g_tcpconnections.erase(i);
-         }
-         else {
-           i->state=TCPConnection::BYTE0;
-           i->startTime=time(0); // needs to be current, TCP is slow anyhow
-         }
-         break;
-       }
+      else {
+       any_cast<TCPConnection&>(g_fdm->getReadParameter(dc->d_socket)).state=TCPConnection::BYTE0;
+       struct timeval now; 
+       gettimeofday(&now, 0); // needs to be updated
+       g_fdm->setReadTTD(dc->d_socket, now, g_tcpTimeout);
       }
-#endif
     }
 
     if(!g_quiet) {
@@ -645,8 +632,7 @@ void handleRunningTCPQuestion(int fd, boost::any& var)
     }
     conn.bytesread+=bytes;
     if(conn.bytesread==conn.qlen) {
-      //      conn.state=TCPConnection::DONE; // this makes us immune from timeouts, from now on *we* are responsible
-      conn.state=TCPConnection::BYTE0; // *wrong* - yes, we want to listen for a new question already, but we shouldn't timeout etc
+      conn.state=TCPConnection::DONE;        // this makes us immune from timeouts, from now on *we* are responsible
       DNSComboWriter* dc=0;
       try {
        dc=new DNSComboWriter(conn.data, conn.qlen, g_now);
@@ -1313,15 +1299,16 @@ int main(int argc, char **argv)
        MT->makeThread(houseKeeping,0);
       }
 
-      if(!(counter%1)) {
+      if(!(counter%11)) {
        typedef vector<pair<int, boost::any> > expired_t;
        expired_t expired=g_fdm->getTimeouts(g_now);
        
        for(expired_t::iterator i=expired.begin() ; i != expired.end(); ++i) {
          TCPConnection conn=any_cast<TCPConnection>(i->second);
-         g_fdm->removeReadFD(i->first);
-         cerr<<"Closed connection with our client "<<i->first<<"\n";
-         conn.closeAndCleanup();
+         if(conn.state != TCPConnection::DONE) {
+           g_fdm->removeReadFD(i->first);
+           conn.closeAndCleanup();
+         }
        }
       }