WiP
[oweals/gnunet.git] / src / util / network.c
index 08121928db6ee69312b571f4c48878ab68aeebeb..d23f1a23d7726da871c06360a69aa485f23272d7 100644 (file)
@@ -451,6 +451,7 @@ GNUNET_NETWORK_socket_recvfrom_amount (const struct GNUNET_NETWORK_Handle
     return GNUNET_NO;
 }
 
+
 /**
  * Read data from a connected socket (always non-blocking).
  * @param desc socket
@@ -774,12 +775,20 @@ GNUNET_NETWORK_fdset_copy (struct GNUNET_NETWORK_FDSet *to,
 #endif
 }
 
+
+/**
+ * Return file descriptor for this network handle
+ *
+ * @param desc wrapper to process
+ * @return POSIX file descriptor
+ */
 int
 GNUNET_NETWORK_get_fd (struct GNUNET_NETWORK_Handle *desc)
 {
   return desc->fd;
 }
 
+
 /**
  * Copy a native fd set
  *
@@ -805,6 +814,7 @@ GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to,
 void GNUNET_NETWORK_fdset_set_native (struct GNUNET_NETWORK_FDSet *to,
                                      int nfd)
 {
+  GNUNET_assert(nfd >= 0);
   FD_SET (nfd, &to->sds);
   to->nsds = GNUNET_MAX (nfd + 1, to->nsds);
 }
@@ -1127,15 +1137,26 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
                 {
                   if (!PeekNamedPipe (fh->h, NULL, 0, NULL, &dwBytes, NULL))
                     {
-                      retcode = -1;
-                      SetErrnoFromWinError (GetLastError ());
+                      DWORD error_code = GetLastError ();
+                      switch (error_code)
+                      {
+                      case ERROR_BROKEN_PIPE:
+                        GNUNET_CONTAINER_slist_add (handles_read,
+                                                  GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
+                                                  fh, sizeof (struct GNUNET_DISK_FileHandle));
+                        retcode++;
+                        break;
+                      default:
+                        retcode = -1;
+                        SetErrnoFromWinError (error_code);
 
     #if DEBUG_NETWORK
-                      GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
-                                           "PeekNamedPipe");
+                        GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
+                                             "PeekNamedPipe");
 
     #endif
-                      goto select_loop_end;
+                        goto select_loop_end;
+                      }
                     }
                   else if (dwBytes)