summaryrefslogtreecommitdiff
path: root/src/dns.cpp
diff options
context:
space:
mode:
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2010-01-18 19:36:41 +0000
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2010-01-18 19:36:41 +0000
commit7e46119759b7099c38f543bd38d0186b9806542f (patch)
treeb31264c454e26566b2e70c2794b89d77f4e28c44 /src/dns.cpp
parent42592c0083505777e8fb8e4bf09182528229a787 (diff)
Remove excessive gettimeofday system calls
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@12293 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/dns.cpp')
-rw-r--r--src/dns.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/dns.cpp b/src/dns.cpp
index ba1e8f2a4..dee83d3ac 100644
--- a/src/dns.cpp
+++ b/src/dns.cpp
@@ -147,6 +147,17 @@ class RequestTimeout : public Timer
}
};
+CachedQuery::CachedQuery(const std::string &res, unsigned int ttl) : data(res)
+{
+ expires = ServerInstance->Time() + ttl;
+}
+
+int CachedQuery::CalcTTLRemaining()
+{
+ int n = expires - ServerInstance->Time();
+ return (n < 0 ? 0 : n);
+}
+
/* Allocate the processing buffer */
DNSRequest::DNSRequest(DNS* dns, int rid, const std::string &original) : dnsobj(dns)
{
@@ -1035,11 +1046,9 @@ void DNS::CleanResolvers(Module* module)
unsigned long DNS::PRNG()
{
unsigned long val = 0;
- timeval n;
serverstats* s = ServerInstance->stats;
- gettimeofday(&n,NULL);
- val = (n.tv_usec ^ (getpid() ^ geteuid()) ^ ((this->currid++)) ^ s->statsAccept) + n.tv_sec;
- val = val + (s->statsCollisions ^ s->statsDnsGood) - s->statsDnsBad;
- val += (s->statsConnects ^ (unsigned long)s->statsSent ^ (unsigned long)s->statsRecv) - ServerInstance->ports.size();
+ val = (rand() ^ this->currid++ ^ s->statsAccept) + ServerInstance->Time_ns();
+ val += (s->statsCollisions ^ s->statsDnsGood) * s->statsDnsBad;
+ val += (s->statsConnects ^ (unsigned long)s->statsSent ^ (unsigned long)s->statsRecv);
return val;
}