merging configs
[oweals/gnunet.git] / src / util / network.c
index fd6687c0f7c5f58657fe7679f5d5e7ae81b41fd0..69db7cd25af973c5792fddf7ce8b6c52121a50df 100644 (file)
@@ -896,6 +896,7 @@ void
 GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst,
                           const struct GNUNET_NETWORK_FDSet *src)
 {
+#ifndef MINGW
   int nfds;
 
   for (nfds = src->nsds; nfds > 0; nfds--)
@@ -906,7 +907,18 @@ GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst,
       if (nfds + 1 > dst->nsds)
         dst->nsds = nfds + 1;
     }
-#ifdef MINGW
+#else
+  /* This is MinGW32-specific implementation that relies on the code that
+   * winsock2.h defines for FD_SET. Namely, it relies on FD_SET checking
+   * that fd being added is not already in the set.
+   * Also relies on us knowing what's inside fd_set (fd_count and fd_array).
+   */
+  int i;
+  for (i = 0; i < src->sds.fd_count; i++)
+    FD_SET (src->sds.fd_array[i], &dst->sds);
+  if (src->nsds > dst->nsds)
+    dst->nsds = src->nsds;
+
   GNUNET_CONTAINER_slist_append (dst->handles, src->handles);
 #endif
 }
@@ -1438,10 +1450,7 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
 
   /* Copy all the writes to the except, so we can detect connect() errors */
   for (i = 0; i < awrite.fd_count; i++)
-  {
-      if (awrite.fd_array[i] != 0 && awrite.fd_array[i] != -1)
-          FD_SET (awrite.fd_array[i], &aexcept);
-  }
+    FD_SET (awrite.fd_array[i], &aexcept);
   if (aread.fd_count > 0 || awrite.fd_count > 0 || aexcept.fd_count > 0)
     selectret = select (1, (rfds != NULL) ? &aread : NULL,
         (wfds != NULL) ? &awrite : NULL, &aexcept, &select_timeout);
@@ -1460,10 +1469,7 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
      have checked that descriptors were in awrite originally before re-adding them from
      aexcept. Luckily, GNUnet never uses aexcept for anything, so this does not become a problem (yet). */
   for (i = 0; i < aexcept.fd_count; i++)
-  {
-    if (aexcept.fd_array[i] != 0 && aexcept.fd_array[i] != -1)
-      FD_SET (aexcept.fd_array[i], &awrite);
-  }
+    FD_SET (aexcept.fd_array[i], &awrite);
 
   /* If our select returned something or is a 0-timed request, then also check the pipes and get out of here! */
   /* Sadly, it means code duplication :( */
@@ -1739,10 +1745,7 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
      * but we don't use OOB data.
      */
     for (i = 0; i < awrite.fd_count; i++)
-    {
-      if (awrite.fd_array[i] != 0 && awrite.fd_array[i] != -1)
-        FD_SET (awrite.fd_array[i], &aexcept);
-    }
+      FD_SET (awrite.fd_array[i], &aexcept);
     ResetEvent (select_finished_event);
     SetEvent (select_standby_event);
   }
@@ -1786,10 +1789,7 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
     }
     /* Check aexcept, add its contents to awrite */
     for (i = 0; i < aexcept.fd_count; i++)
-    {
-      if (aexcept.fd_array[i] != 0 && aexcept.fd_array[i] != -1)
-        FD_SET (aexcept.fd_array[i], &awrite);
-    }
+      FD_SET (aexcept.fd_array[i], &awrite);
   }
 
   returnedpos = returncode - WAIT_OBJECT_0;