summaryrefslogtreecommitdiff
path: root/src/dnsqueue.cpp
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-04-03 04:38:22 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-04-03 04:38:22 +0000
commit786dfff31131d844e27e700b289c3070258de084 (patch)
tree6935a80a722ccc9d0249cc12f4aaf22433a0fe3a /src/dnsqueue.cpp
parent48e25fcfd24027d45540d8e341cd6daf13de16b9 (diff)
Major optimizations! now uses under 1% cpu all the time whilst idle
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@959 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/dnsqueue.cpp')
-rw-r--r--src/dnsqueue.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/dnsqueue.cpp b/src/dnsqueue.cpp
index 71ab99019..0c9adf7a2 100644
--- a/src/dnsqueue.cpp
+++ b/src/dnsqueue.cpp
@@ -162,6 +162,7 @@ extern command_table cmdlist;
extern ClassVector Classes;
extern char DNSServer[MAXBUF];
+long max_fd_alloc = 0;
class Lookup {
private:
@@ -244,9 +245,11 @@ public:
int GetFD()
{
userrec* usr = Find(u);
- if (usr)
- return usr->fd;
- else return 0;
+ if (!usr)
+ return 0;
+ if (usr->dns_done)
+ return 0;
+ return usr->fd;
}
};
@@ -271,6 +274,10 @@ bool lookup_dns(std::string nick)
return true;
}
}
+ // calculate the maximum value, this saves cpu time later
+ for (int p = 0; p < MAXBUF; p++)
+ if (dnsq[p].GetFD())
+ max_fd_alloc = p;
}
else
{
@@ -283,7 +290,7 @@ bool lookup_dns(std::string nick)
void dns_poll()
{
// do we have items in the queue?
- for (int j = 0; j < MAXBUF; j++)
+ for (int j = 0; j <= max_fd_alloc; j++)
{
// are any ready, or stale?
if (dnsq[j].GetFD())
@@ -294,5 +301,11 @@ void dns_poll()
}
}
}
+ // looks like someones freed an item, recalculate end of list.
+ if ((!dnsq[max_fd_alloc].GetFD()) && (max_fd_alloc != 0))
+ for (int p = 0; p < MAXBUF; p++)
+ if (dnsq[p].GetFD())
+ max_fd_alloc = p;
+
}