]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspircd.cpp
Dns poll not called often enough
[user/henk/code/inspircd.git] / src / inspircd.cpp
index 1f7487242b6a6640a10fc0c180f99c002c14ebe6..21e3bffd97759d51492b86151b46a49208cc9af3 100644 (file)
@@ -109,7 +109,7 @@ int openSockfd[MAXSOCKS];
 bool nofork = false;
 bool unlimitcore = false;
 
-time_t TIME = time(NULL);
+time_t TIME = time(NULL), OLDTIME = time(NULL);
 
 #ifdef USE_KQUEUE
 int kq, lkq, skq;
@@ -4069,7 +4069,9 @@ int InspIRCd(char** argv, int argc)
        WritePID(PID);
          
        /* setup select call */
+#ifndef USE_KQUEUE
        FD_ZERO(&selectFds);
+#endif
        log(DEBUG,"InspIRCd: startup: zero selects");
        log(VERBOSE,"InspIRCd: startup: portCount = %lu", (unsigned long)portCount);
        
@@ -4173,6 +4175,7 @@ int InspIRCd(char** argv, int argc)
 
 #ifdef USE_KQUEUE
         struct kevent ke;
+       struct kevent ke_list[33];
         struct timespec ts;
 #endif
         fd_set serverfds;
@@ -4187,7 +4190,7 @@ int InspIRCd(char** argv, int argc)
         tval.tv_usec = 10000L;
         tval.tv_sec = 0;
         int total_in_this_set = 0;
-       int i = 0, v = 0;
+       int i = 0, v = 0, j = 0, cycle_iter = 0;
        bool expire_run = false;
          
        /* main loop, this never returns */
@@ -4196,13 +4199,16 @@ int InspIRCd(char** argv, int argc)
 #ifdef _POSIX_PRIORITY_SCHEDULING
                sched_yield();
 #endif
-                // poll dns queue
-                dns_poll();
+#ifndef USE_KQUEUE
                FD_ZERO(&sfd);
+#endif
 
                // we only read time() once per iteration rather than tons of times!
+               OLDTIME = TIME;
                TIME = time(NULL);
 
+               dns_poll();
+
                // *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 (((TIME % 5) == 0) && (!expire_run))
@@ -4304,7 +4310,9 @@ int InspIRCd(char** argv, int argc)
        
        while (count2 != clientlist.end())
        {
+#ifndef USE_KQUEUE
                FD_ZERO(&sfd);
+#endif
 
                total_in_this_set = 0;
 
@@ -4383,11 +4391,12 @@ int InspIRCd(char** argv, int argc)
                        endingiter = count2;
                                count2 = xcount; // roll back to where we were
 #else
-                       dns_poll();
                        // KQUEUE: We don't go through a loop to fill the fd_set so instead we must manually do this loop every now and again.
                        // TODO: We dont need to do all this EVERY loop iteration, tone down the visits to this if we're using kqueue.
-                       while (count2 != clientlist.end())
+                       cycle_iter++;
+                       if (cycle_iter > 10) while (count2 != clientlist.end())
                        {
+                               cycle_iter = 0;
                                if (count2 != clientlist.end())
                                {
                                        curr = count2->second;
@@ -4658,8 +4667,8 @@ int InspIRCd(char** argv, int argc)
 #else
        ts.tv_sec = 0;
        ts.tv_nsec = 30000L;
-       i = kevent(lkq, NULL, 0, &ke, 1, &ts);
-       if (i > 0)
+       i = kevent(lkq, NULL, 0, ke_list, 32, &ts);
+       if (i > 0) for (j = 0; j < i; j++)
        {
                log(DEBUG,"kqueue: Listening socket event, i=%d, ke.ident=%d",i,ke.ident);
                // this isnt as efficient as it could be, we could create a reference table
@@ -4668,7 +4677,7 @@ int InspIRCd(char** argv, int argc)
                // compared to the number of clients (possibly over 2000)
                for (count = 0; count < boundPortCount; count++)
                {
-                       if (ke.ident == openSockfd[count])
+                       if (ke_list[j].ident == openSockfd[count])
                        {
 #endif
                                char target[MAXBUF], resolved[MAXBUF];
@@ -4691,7 +4700,7 @@ int InspIRCd(char** argv, int argc)
                                        AddClient(incomingSockfd, resolved, ports[count], false, inet_ntoa (client.sin_addr));
                                        log(DEBUG,"InspIRCd: adding client on port %lu fd=%lu",(unsigned long)ports[count],(unsigned long)incomingSockfd);
                                }
-                               goto label;
+                               //goto label;
                        }
                }
        }