fixing off by 1000 in select code
authorChristian Grothoff <christian@grothoff.org>
Thu, 1 Oct 2009 22:19:24 +0000 (22:19 +0000)
committerChristian Grothoff <christian@grothoff.org>
Thu, 1 Oct 2009 22:19:24 +0000 (22:19 +0000)
src/util/network.c

index 4ac46fa0b06282bf45935aa6ec909f902f33ca43..dff1277358f2389ac53d7a57ed5775f4da52ff39 100644 (file)
@@ -632,23 +632,25 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
 \r
   nfds = 0;\r
 \r
-  if (rfds)\r
+  if (NULL != rfds)\r
     nfds = rfds->nsds;\r
-  if (wfds && wfds->nsds > nfds)\r
-    nfds = wfds->nsds;\r
-  if (efds && efds->nsds > nfds)\r
-    nfds = efds->nsds;\r
+  if (NULL != wfds)\r
+    nfds = GNUNET_MAX (nfds, wfds->nsds);\r
+  if (NULL != efds)\r
+    nfds = GNUNET_MAX (nfds, efds->nsds);\r
 \r
 #ifndef MINGW\r
   struct timeval tv;\r
 \r
   tv.tv_sec = timeout.value / GNUNET_TIME_UNIT_SECONDS.value;\r
-  tv.tv_usec = (timeout.value - (tv.tv_sec * GNUNET_TIME_UNIT_SECONDS.value))\r
-    / GNUNET_TIME_UNIT_MILLISECONDS.value;\r
-\r
-  return select (nfds + 1, rfds ? &rfds->sds : NULL, wfds ? &wfds->sds : NULL,\r
-      efds ? &efds->sds : NULL, timeout.value\r
-          == GNUNET_TIME_UNIT_FOREVER_REL.value ? NULL : &tv);\r
+  tv.tv_usec = 1000 * (timeout.value - (tv.tv_sec * GNUNET_TIME_UNIT_SECONDS.value));\r
+  return select (nfds + 1, \r
+                (rfds != NULL) ? &rfds->sds : NULL, \r
+                (wfds != NULL) ? &wfds->sds : NULL,\r
+                (efds != NULL) ? &efds->sds : NULL, \r
+                (timeout.value == GNUNET_TIME_UNIT_FOREVER_REL.value) \r
+                ? NULL \r
+                : &tv);\r
 #else\r
   DWORD limit;\r
   fd_set sock_read, sock_write, sock_except;\r
@@ -670,7 +672,6 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
   if (!(rfds || wfds || efds))\r
     {\r
       Sleep (ms_total);\r
-\r
       return 0;\r
     }\r
 \r