diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-07-14 17:09:23 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-07-14 17:09:23 +0000 |
commit | cedcec295b9d28200f013662d67011c1bff180ff (patch) | |
tree | 4bcf14f94109f9091cb2be3a55f66a8cc6ae8144 /src/util | |
parent | b247968ea031953cc33f88372962b9bb69052b8a (diff) | |
download | gnunet-cedcec295b9d28200f013662d67011c1bff180ff.tar.gz gnunet-cedcec295b9d28200f013662d67011c1bff180ff.zip |
mantis 1735
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/network.c | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/src/util/network.c b/src/util/network.c index 814246ea0..f4190162e 100644 --- a/src/util/network.c +++ b/src/util/network.c | |||
@@ -29,7 +29,9 @@ | |||
29 | #include "disk.h" | 29 | #include "disk.h" |
30 | #include "gnunet_container_lib.h" | 30 | #include "gnunet_container_lib.h" |
31 | 31 | ||
32 | #define DEBUG_NETWORK GNUNET_YES | 32 | #define DEBUG_NETWORK GNUNET_NO |
33 | |||
34 | #define DEBUG_W32_CYCLES GNUNET_NO | ||
33 | 35 | ||
34 | #ifndef INVALID_SOCKET | 36 | #ifndef INVALID_SOCKET |
35 | #define INVALID_SOCKET -1 | 37 | #define INVALID_SOCKET -1 |
@@ -1106,6 +1108,8 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1106 | struct timeval tvslice; | 1108 | struct timeval tvslice; |
1107 | int retcode; | 1109 | int retcode; |
1108 | DWORD ms_total; | 1110 | DWORD ms_total; |
1111 | /* Number of milliseconds per cycle. Adapted on the fly */ | ||
1112 | static unsigned int cycle_delay = 20; | ||
1109 | 1113 | ||
1110 | #define SAFE_FD_ISSET(fd, set) (set != NULL && FD_ISSET(fd, set)) | 1114 | #define SAFE_FD_ISSET(fd, set) (set != NULL && FD_ISSET(fd, set)) |
1111 | 1115 | ||
@@ -1145,6 +1149,12 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1145 | FD_ZERO (&aread); | 1149 | FD_ZERO (&aread); |
1146 | FD_ZERO (&awrite); | 1150 | FD_ZERO (&awrite); |
1147 | FD_ZERO (&aexcept); | 1151 | FD_ZERO (&aexcept); |
1152 | |||
1153 | #if DEBUG_W32_CYCLES | ||
1154 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1155 | "Starting a cycle, delay is %dms\n", cycle_delay); | ||
1156 | #endif | ||
1157 | |||
1148 | limit = GetTickCount () + ms_total; | 1158 | limit = GetTickCount () + ms_total; |
1149 | 1159 | ||
1150 | do | 1160 | do |
@@ -1160,7 +1170,7 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1160 | FD_COPY (&sock_write, &awrite); | 1170 | FD_COPY (&sock_write, &awrite); |
1161 | FD_COPY (&sock_except, &aexcept); | 1171 | FD_COPY (&sock_except, &aexcept); |
1162 | tvslice.tv_sec = 0; | 1172 | tvslice.tv_sec = 0; |
1163 | tvslice.tv_usec = 100000; | 1173 | tvslice.tv_usec = cycle_delay; |
1164 | if ((retcode = | 1174 | if ((retcode = |
1165 | select (nfds + 1, &aread, &awrite, &aexcept, | 1175 | select (nfds + 1, &aread, &awrite, &aexcept, |
1166 | &tvslice)) == SOCKET_ERROR) | 1176 | &tvslice)) == SOCKET_ERROR) |
@@ -1301,8 +1311,26 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1301 | } | 1311 | } |
1302 | } | 1312 | } |
1303 | select_loop_end: | 1313 | select_loop_end: |
1314 | if (retcode == 0) | ||
1315 | { | ||
1316 | /* Missed an I/O - double the cycle time */ | ||
1317 | cycle_delay = cycle_delay * 2 > 250 ? 250 : cycle_delay * 1.4; | ||
1318 | #if DEBUG_W32_CYCLES | ||
1319 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1320 | "The cycle missed, increased the delay to %dms\n", cycle_delay); | ||
1321 | #endif | ||
1322 | } | ||
1323 | else | ||
1324 | { | ||
1325 | /* Successfully selected something - decrease the cycle time */ | ||
1326 | cycle_delay -= cycle_delay > 2 ? 2 : 0; | ||
1327 | #if DEBUG_W32_CYCLES | ||
1328 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1329 | "The cycle hit, decreased the delay to %dms\n", cycle_delay); | ||
1330 | #endif | ||
1331 | } | ||
1304 | if (retcode == 0 && nfds == 0) | 1332 | if (retcode == 0 && nfds == 0) |
1305 | Sleep (GNUNET_MIN (100, limit - GetTickCount ())); | 1333 | Sleep (GNUNET_MIN (cycle_delay * 1000, limit - GetTickCount ())); |
1306 | } | 1334 | } |
1307 | while (retcode == 0 && (ms_total == INFINITE || GetTickCount () < limit)); | 1335 | while (retcode == 0 && (ms_total == INFINITE || GetTickCount () < limit)); |
1308 | 1336 | ||