]> granicus.if.org Git - pdns/commitdiff
remove some dead code, plus attempt to fix up tcp connection count accounting, adding...
authorBert Hubert <bert.hubert@netherlabs.nl>
Sat, 26 Jun 2010 08:36:21 +0000 (08:36 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Sat, 26 Jun 2010 08:36:21 +0000 (08:36 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1652 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/pdns_recursor.cc
pdns/rec_channel_rec.cc
pdns/syncres.hh

index 375b879a9b8ddcc9d1f08a44bf14903579125662..5f8c2ad339395fd436be3afd1d21fe4e7d50ead8 100644 (file)
@@ -452,14 +452,14 @@ void TCPConnection::closeAndCleanup(int fd, const ComboAddress& remote)
   Utility::closesocket(fd);
   if(!(*t_tcpClientCounts)[remote]--) 
     t_tcpClientCounts->erase(remote);
-  s_currentConnections--;
+  decCurrentConnections();
 }
 void TCPConnection::closeAndCleanup()
 {
   closeAndCleanup(fd, remote);
 }
 
-unsigned int TCPConnection::s_currentConnections; 
+volatile unsigned int TCPConnection::s_currentConnections; 
 void handleRunningTCPQuestion(int fd, FDMultiplexer::funcparam_t& var);
 
 void updateRcodeStats(int res)
@@ -512,6 +512,7 @@ void startDoResolve(void *p)
     int res;
 
     bool variableAnswer = false;
+    // if there is a PowerDNSLua active, and it 'took' the query in preResolve, we don't launch beginResolve
     if(!t_pdl->get() || !(*t_pdl)->preresolve(dc->d_remote, g_listenSocketsAddresses[dc->d_socket], dc->d_mdp.d_qname, QType(dc->d_mdp.d_qtype), ret, res, &variableAnswer)) {
        res = sr.beginResolve(dc->d_mdp.d_qname, QType(dc->d_mdp.d_qtype), dc->d_mdp.d_qclass, ret);
 
@@ -602,7 +603,6 @@ void startDoResolve(void *p)
         tc.state=TCPConnection::BYTE0;
         tc.remote=dc->d_remote;
         Utility::gettimeofday(&g_now, 0); // needs to be updated
-        tc.startTime=g_now.tv_sec;
         t_fdm->addReadFD(tc.fd, handleRunningTCPQuestion, tc);
         t_fdm->setReadTTD(tc.fd, g_now, g_tcpTimeout);
       }
@@ -761,7 +761,7 @@ void handleRunningTCPQuestion(int fd, FDMultiplexer::funcparam_t& var)
       else {
         ++g_stats.qcounter;
         ++g_stats.tcpqcounter;
-        MT->makeThread(startDoResolve, dc); // deletes dc
+        MT->makeThread(startDoResolve, dc); // deletes dc, will set state to BYTE0 again
         return;
       }
     }
@@ -801,8 +801,7 @@ void handleNewTCPQuestion(int fd, FDMultiplexer::funcparam_t& )
     tc.fd=newsock;
     tc.state=TCPConnection::BYTE0;
     tc.remote=addr;
-    tc.startTime=g_now.tv_sec;
-    TCPConnection::s_currentConnections++;
+    TCPConnection::incCurrentConnections();
     t_fdm->addReadFD(tc.fd, handleRunningTCPQuestion, tc);
 
     struct timeval now;
@@ -1824,14 +1823,14 @@ try
     // 'run' updates g_now for us
 
     if(listenOnTCP) {
-      if(TCPConnection::s_currentConnections > maxTcpClients) {  // shutdown, too many connections
+      if(TCPConnection::getCurrentConnections() > maxTcpClients) {  // shutdown, too many connections
         for(tcpListenSockets_t::iterator i=g_tcpListenSockets.begin(); i != g_tcpListenSockets.end(); ++i)
           t_fdm->removeReadFD(*i);
         listenOnTCP=false;
       }
     }
     else {
-      if(TCPConnection::s_currentConnections <= maxTcpClients) {  // reenable
+      if(TCPConnection::getCurrentConnections() <= maxTcpClients) {  // reenable
         for(tcpListenSockets_t::iterator i=g_tcpListenSockets.begin(); i != g_tcpListenSockets.end(); ++i)
           t_fdm->addReadFD(*i, handleNewTCPQuestion);
         listenOnTCP=true;
index 52dce418f2438ee31b47a82336c97d151d80772e..0ff62a2305bf22319f240a996417d32f6c35adee 100644 (file)
@@ -394,7 +394,7 @@ RecursorControlParser::RecursorControlParser()
   addGetStat("throttled-out", &SyncRes::s_throttledqueries);
   addGetStat("unreachables", &SyncRes::s_unreachables);
   addGetStat("chain-resends", &g_stats.chainResends);
-  addGetStat("tcp-clients", &TCPConnection::s_currentConnections);
+  addGetStat("tcp-clients", boost::bind(TCPConnection::getCurrentConnections));
 
   addGetStat("edns-ping-matches", &g_stats.ednsPingMatches);
   addGetStat("edns-ping-mismatches", &g_stats.ednsPingMismatches);
index 3df31b36157acc7b1fc6f7524f39c6510cbef262..9d12650ed13a18f4d10e4e3a2a6720989ddd7949 100644 (file)
@@ -480,19 +480,23 @@ struct RecursorStats
 };
 
 //! represents a running TCP/IP client session
-struct TCPConnection
+class TCPConnection
 {
+public:
   int fd;
   enum stateenum {BYTE0, BYTE1, GETQUESTION, DONE} state;
   int qlen;
   int bytesread;
   ComboAddress remote;
   char data[65535];
-  time_t startTime;
 
   static void closeAndCleanup(int fd, const ComboAddress& remote);
   void closeAndCleanup();
-  static unsigned int s_currentConnections; //!< total number of current TCP connections
+  static unsigned int getCurrentConnections() { return s_currentConnections; }
+  static void incCurrentConnections() { s_currentConnections++; }
+  static void decCurrentConnections() { s_currentConnections--; }
+private:
+  static volatile unsigned int s_currentConnections; //!< total number of current TCP connections
 };