gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r15963 - gnunet/src/util


From: gnunet
Subject: [GNUnet-SVN] r15963 - gnunet/src/util
Date: Thu, 14 Jul 2011 19:09:23 +0200

Author: grothoff
Date: 2011-07-14 19:09:23 +0200 (Thu, 14 Jul 2011)
New Revision: 15963

Modified:
   gnunet/src/util/network.c
Log:
mantis 1735

Modified: gnunet/src/util/network.c
===================================================================
--- gnunet/src/util/network.c   2011-07-14 16:44:45 UTC (rev 15962)
+++ gnunet/src/util/network.c   2011-07-14 17:09:23 UTC (rev 15963)
@@ -29,8 +29,10 @@
 #include "disk.h"
 #include "gnunet_container_lib.h"
 
-#define DEBUG_NETWORK GNUNET_YES
+#define DEBUG_NETWORK GNUNET_NO
 
+#define DEBUG_W32_CYCLES GNUNET_NO
+
 #ifndef INVALID_SOCKET
 #define INVALID_SOCKET -1
 #endif
@@ -1106,6 +1108,8 @@
   struct timeval tvslice;
   int retcode;
   DWORD ms_total;
+  /* Number of milliseconds per cycle. Adapted on the fly */
+  static unsigned int cycle_delay = 20;
 
 #define SAFE_FD_ISSET(fd, set)  (set != NULL && FD_ISSET(fd, set))
 
@@ -1145,6 +1149,12 @@
   FD_ZERO (&aread);
   FD_ZERO (&awrite);
   FD_ZERO (&aexcept);
+
+#if DEBUG_W32_CYCLES
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Starting a cycle, delay is %dms\n", cycle_delay);
+#endif
+
   limit = GetTickCount () + ms_total;
 
   do
@@ -1160,7 +1170,7 @@
           FD_COPY (&sock_write, &awrite);
           FD_COPY (&sock_except, &aexcept);
           tvslice.tv_sec = 0;
-          tvslice.tv_usec = 100000;
+          tvslice.tv_usec = cycle_delay;
           if ((retcode =
                select (nfds + 1, &aread, &awrite, &aexcept,
                        &tvslice)) == SOCKET_ERROR)
@@ -1301,8 +1311,26 @@
             }
         }
     select_loop_end:
+      if (retcode == 0)
+      {
+        /* Missed an I/O - double the cycle time */
+        cycle_delay = cycle_delay * 2 > 250 ? 250 : cycle_delay * 1.4;
+#if DEBUG_W32_CYCLES
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                    "The cycle missed, increased the delay to %dms\n", 
cycle_delay);
+#endif
+      }
+      else
+      {
+        /* Successfully selected something - decrease the cycle time */
+        cycle_delay -= cycle_delay > 2 ? 2 : 0;
+#if DEBUG_W32_CYCLES
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                    "The cycle hit, decreased the delay to %dms\n", 
cycle_delay);
+#endif
+      }
       if (retcode == 0 && nfds == 0)
-        Sleep (GNUNET_MIN (100, limit - GetTickCount ()));
+        Sleep (GNUNET_MIN (cycle_delay * 1000, limit - GetTickCount ()));
     }
   while (retcode == 0 && (ms_total == INFINITE || GetTickCount () < limit));
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]