From: Bert Hubert Date: Sun, 30 May 2010 18:18:51 +0000 (+0000) Subject: implement 'rec_control get tcp-clients' to debug TCP client issue X-Git-Tag: rec-3.3~79 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0e408828b6a7cf981d7a363bf5c1062b2cf81d09;p=pdns implement 'rec_control get tcp-clients' to debug TCP client issue git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1623 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 7b8191a9d..9bedfc3a9 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -446,29 +446,18 @@ static void writePid(void) typedef map tcpClientCounts_t; tcpClientCounts_t __thread* t_tcpClientCounts; -struct TCPConnection + +void TCPConnection::closeAndCleanup(int fd, const ComboAddress& remote) { - 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) - { - Utility::closesocket(fd); - if(!(*t_tcpClientCounts)[remote]--) - t_tcpClientCounts->erase(remote); - s_currentConnections--; - } - void closeAndCleanup() - { - closeAndCleanup(fd, remote); - } - static unsigned int s_currentConnections; //!< total number of current TCP connections -}; + Utility::closesocket(fd); + if(!(*t_tcpClientCounts)[remote]--) + t_tcpClientCounts->erase(remote); + s_currentConnections--; +} +void TCPConnection::closeAndCleanup() +{ + closeAndCleanup(fd, remote); +} unsigned int TCPConnection::s_currentConnections; void handleRunningTCPQuestion(int fd, FDMultiplexer::funcparam_t& var); diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index 10760b407..7edc81ffa 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -393,6 +393,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("edns-ping-matches", &g_stats.ednsPingMatches); addGetStat("edns-ping-mismatches", &g_stats.ednsPingMismatches); diff --git a/pdns/syncres.hh b/pdns/syncres.hh index 22645a2c0..b6b857d14 100644 --- a/pdns/syncres.hh +++ b/pdns/syncres.hh @@ -478,6 +478,23 @@ struct RecursorStats time_t startupTime; }; +//! represents a running TCP/IP client session +struct TCPConnection +{ + 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 +}; + + struct RemoteKeeper { typedef vector remotes_t;