Index: /trunk/pdns/pdns/pdns_recursor.cc
===================================================================
--- /trunk/pdns/pdns/pdns_recursor.cc	(revision 721)
+++ /trunk/pdns/pdns/pdns_recursor.cc	(revision 722)
@@ -526,24 +526,11 @@
 	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;
-	}
-      }
-#endif
+      }
+      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);
+      }
     }
 
@@ -646,6 +633,5 @@
     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 {
@@ -1314,5 +1300,5 @@
       }
 
-      if(!(counter%1)) {
+      if(!(counter%11)) {
 	typedef vector<pair<int, boost::any> > expired_t;
 	expired_t expired=g_fdm->getTimeouts(g_now);
@@ -1320,7 +1306,8 @@
 	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();
+	  }
 	}
       }
Index: /trunk/pdns/pdns/mplexer.hh
===================================================================
--- /trunk/pdns/pdns/mplexer.hh	(revision 720)
+++ /trunk/pdns/pdns/mplexer.hh	(revision 722)
@@ -78,4 +78,11 @@
   }
 
+  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)
   {
@@ -97,4 +104,5 @@
   
   virtual std::string getName() = 0;
+
 
 protected:
