Returns now GNUNET_SYSERR
[oweals/gnunet.git] / src / util / network.c
index a1142d43341b80c0b99d7ef69494529a4431ede4..58d67ed19fd36ba8933e4f666d30e91e47e5d419 100644 (file)
@@ -161,9 +161,9 @@ socket_set_inheritable (const struct GNUNET_NETWORK_Handle *h)
 static void
 socket_set_nosigpipe (const struct GNUNET_NETWORK_Handle *h)
 {
-  int value = 1;
+  int abs_value = 1;
   if (0 !=
-      setsockopt (h->fd, SOL_SOCKET, SO_NOSIGPIPE, &value, sizeof (value)))
+      setsockopt (h->fd, SOL_SOCKET, SO_NOSIGPIPE, &abs_value, sizeof (abs_value)))
     GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
 }
 #endif
@@ -184,8 +184,8 @@ socket_set_nodelay (const struct GNUNET_NETWORK_Handle *h)
   if (0 != setsockopt (h->fd, IPPROTO_TCP, TCP_NODELAY, &value, sizeof (value)))
     GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
 #else
-  const char * value = "1";
-  if (0 != setsockopt (h->fd, IPPROTO_TCP, TCP_NODELAY, value, sizeof (value)))
+  const char * abs_value = "1";
+  if (0 != setsockopt (h->fd, IPPROTO_TCP, TCP_NODELAY, abs_value, sizeof (abs_value)))
     GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
 #endif 
 }
@@ -899,6 +899,7 @@ int
 GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1,
                               const struct GNUNET_NETWORK_FDSet *fds2)
 {
+#ifndef MINGW
   int nfds;
 
   nfds = fds1->nsds;
@@ -910,26 +911,36 @@ GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1,
       if (FD_ISSET (nfds, &fds1->sds) && FD_ISSET (nfds, &fds2->sds))
        return GNUNET_YES;
     }
-#ifdef MINGW
-  {
-    struct GNUNET_CONTAINER_SList_Iterator *it;
+#else
+  struct GNUNET_CONTAINER_SList_Iterator *it;
+  HANDLE *h;
+  int i;
+  int j;
 
-    for (it = GNUNET_CONTAINER_slist_begin (fds1->handles);
-         GNUNET_CONTAINER_slist_end (it) != GNUNET_YES;
-         GNUNET_CONTAINER_slist_next (it))
-      {
-        HANDLE *h;
-
-        h = (HANDLE *) GNUNET_CONTAINER_slist_get ((const struct GNUNET_CONTAINER_SList_Iterator *)it, NULL);
-        if (GNUNET_CONTAINER_slist_contains
-            (fds2->handles, h, sizeof (HANDLE)))
-          {
-            GNUNET_CONTAINER_slist_iter_destroy (it);
-            return GNUNET_YES;
-          }
-      }
-    GNUNET_CONTAINER_slist_iter_destroy (it);
+  /*This code is somewhat hacky, we are not supposed to know what's
+    inside of fd_set; also the O(n^2) is really bad... */
+
+  for (i = 0; i < fds1->sds.fd_count; i++)
+  {
+    for (j = 0; j < fds2->sds.fd_count; j++)
+    {
+      if (fds1->sds.fd_array[i] == fds2->sds.fd_array[j])
+        return GNUNET_YES;
+    }
   }
+  it = GNUNET_CONTAINER_slist_begin (fds1->handles);
+  while (GNUNET_CONTAINER_slist_end (it) != GNUNET_YES)
+    {
+      h = (HANDLE *) GNUNET_CONTAINER_slist_get (it, NULL);
+      if (GNUNET_CONTAINER_slist_contains
+          (fds2->handles, h, sizeof (HANDLE)))
+        {
+          GNUNET_CONTAINER_slist_iter_destroy (it);
+          return GNUNET_YES;
+        }
+      GNUNET_CONTAINER_slist_next (it);
+    }
+  GNUNET_CONTAINER_slist_iter_destroy (it);
 #endif
   return GNUNET_NO;
 }
@@ -1010,10 +1021,10 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
     }
 
   struct timeval tv;
-  tv.tv_sec = timeout.value / GNUNET_TIME_UNIT_SECONDS.value;
+  tv.tv_sec = timeout.rel_value / GNUNET_TIME_UNIT_SECONDS.rel_value;
   tv.tv_usec =
-    1000 * (timeout.value - (tv.tv_sec * GNUNET_TIME_UNIT_SECONDS.value));
-  if ((nfds == 0) && (timeout.value == GNUNET_TIME_UNIT_FOREVER_REL.value)
+    1000 * (timeout.rel_value - (tv.tv_sec * GNUNET_TIME_UNIT_SECONDS.rel_value));
+  if ((nfds == 0) && (timeout.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value)
 #ifdef MINGW
       && handles == 0
 #endif
@@ -1030,7 +1041,7 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
                  (rfds != NULL) ? &rfds->sds : NULL,
                  (wfds != NULL) ? &wfds->sds : NULL,
                  (efds != NULL) ? &efds->sds : NULL,
-                 (timeout.value == GNUNET_TIME_UNIT_FOREVER_REL.value)
+                 (timeout.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value)
                  ? NULL : &tv);
 
 #else
@@ -1048,11 +1059,11 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
 #define SAFE_FD_ISSET(fd, set)  (set != NULL && FD_ISSET(fd, set))
 
   /* calculate how long we need to wait in milliseconds */
-  if (timeout.value == GNUNET_TIME_UNIT_FOREVER_REL.value)
+  if (timeout.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value)
     ms_total = INFINITE;
 
   else
-    ms_total = timeout.value / GNUNET_TIME_UNIT_MILLISECONDS.value;
+    ms_total = timeout.rel_value / GNUNET_TIME_UNIT_MILLISECONDS.rel_value;
 
   /* select() may be used as a portable way to sleep */
   if (!(rfds || wfds || efds))