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)
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);
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);
}
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;
}
}
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;
// '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;
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);
};
//! 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
};