diff options
-rw-r--r-- | src/dnsqueue.cpp | 21 | ||||
-rw-r--r-- | src/inspircd.cpp | 29 |
2 files changed, 34 insertions, 16 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; + } diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 53ac1dfab..00e48317b 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -3391,20 +3391,27 @@ int InspIRCd(void) #ifdef _POSIX_PRIORITY_SCHEDULING sched_yield(); #endif - // update the status of klines, etc - expire_lines(); + // poll dns queue + dns_poll(); fd_set sfd; timeval tval; FD_ZERO(&sfd); - // poll dns queue - dns_poll(); - user_hash::iterator count2 = clientlist.begin(); // *FIX* Instead of closing sockets in kill_link when they receive the ERROR :blah line, we should queue // them in a list, then reap the list every second or so. + if ((reap_counter % 50) == 0) + { + // These functions eat cpu, and should not be done so often! + + // update the status of klines, etc + expire_lines(); +#ifdef _POSIX_PRIORITY_SCHEDULING + sched_yield(); +#endif + } if (reap_counter>300) { if (fd_reap.size() > 0) @@ -3432,7 +3439,7 @@ int InspIRCd(void) FD_SET(me[x]->fd, &serverfds); } - tvs.tv_usec = 0; + tvs.tv_usec = 5000; tvs.tv_sec = 0; int servresult = select(32767, &serverfds, NULL, NULL, &tvs); @@ -3496,7 +3503,8 @@ int InspIRCd(void) while (count2 != clientlist.end()) { char data[10240]; - tval.tv_usec = tval.tv_sec = 0; + tval.tv_usec = 5000; + tval.tv_sec = 0; FD_ZERO(&sfd); int total_in_this_set = 0; @@ -3567,7 +3575,7 @@ int InspIRCd(void) int v = 0; - tval.tv_usec = 0; + tval.tv_usec = 5000; tval.tv_sec = 0; selectResult2 = select(65535, &sfd, NULL, NULL, &tval); @@ -3583,14 +3591,11 @@ int InspIRCd(void) result = EAGAIN; if ((count2a->second->fd != -1) && (FD_ISSET (count2a->second->fd, &sfd))) { - log(DEBUG,"Reading fd %d",count2a->second->fd); memset(data, 0, 10240); result = read(count2a->second->fd, data, 10240); if (result) { - if (result > 0) - log(DEBUG,"Read %d characters from socket",result); userrec* current = count2a->second; int currfd = current->fd; char* l = strtok(data,"\n"); @@ -3689,7 +3694,7 @@ int InspIRCd(void) FD_SET (openSockfd[count], &selectFds); } - tv.tv_usec = 1; + tv.tv_usec = 5000; selectResult = select(MAXSOCKS, &selectFds, NULL, NULL, &tv); /* select is reporting a waiting socket. Poll them all to find out which */ |