gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r19140 - in gnunet/src: fs util


From: gnunet
Subject: [GNUnet-SVN] r19140 - in gnunet/src: fs util
Date: Sat, 14 Jan 2012 19:31:25 +0100

Author: grothoff
Date: 2012-01-14 19:31:25 +0100 (Sat, 14 Jan 2012)
New Revision: 19140

Modified:
   gnunet/src/fs/fs_dirmetascan.c
   gnunet/src/util/disk.c
Log:
-LRN: fix pipe writing and progress write

Modified: gnunet/src/fs/fs_dirmetascan.c
===================================================================
--- gnunet/src/fs/fs_dirmetascan.c      2012-01-14 16:04:58 UTC (rev 19139)
+++ gnunet/src/fs/fs_dirmetascan.c      2012-01-14 18:31:25 UTC (rev 19140)
@@ -346,61 +346,61 @@
     char is_directory, enum GNUNET_DirScannerProgressUpdateReason reason)
 {
   size_t filename_len;
-  size_t wr;
+  ssize_t wr;
   size_t total_write;
   if ((adc->do_stop || should_stop (adc)) && reason != 
GNUNET_DIR_SCANNER_ASKED_TO_STOP
       && reason != GNUNET_DIR_SCANNER_FINISHED)
     return 1;
-  total_write = wr = GNUNET_DISK_file_write (adc->progress_write,
-      &reason, sizeof (reason));
-  while (wr > 0 && total_write < sizeof (reason))
+  total_write = 0;
+  wr = 1;
+  while ((wr > 0 || errno == EAGAIN) && total_write < sizeof (reason))
   {
-    total_write = wr = GNUNET_DISK_file_write (adc->progress_write,
+    wr = GNUNET_DISK_file_write (adc->progress_write,
       &((char *)&reason)[total_write], sizeof (reason) - total_write);
     if (wr > 0)
       total_write += wr;
   }
-  if (sizeof (reason) != wr)
-    return 1;
+  if (sizeof (reason) != total_write)
+    return adc->do_stop = 1;
   if (filename)
     filename_len = strlen (filename) + 1;
   else
     filename_len = 0;
-  total_write = wr = GNUNET_DISK_file_write (adc->progress_write,
-      &filename_len, sizeof (size_t));
-  while (wr > 0 && total_write < sizeof (size_t))
+  total_write = 0;
+  wr = 1;
+  while ((wr > 0 || errno == EAGAIN) && total_write < sizeof (size_t))
   {
-    total_write = wr = GNUNET_DISK_file_write (adc->progress_write,
+    wr = GNUNET_DISK_file_write (adc->progress_write,
       &((char *)&filename_len)[total_write], sizeof (size_t) - total_write);
     if (wr > 0)
       total_write += wr;
   }
-  if (sizeof (size_t) != wr)
-    return 1;
+  if (sizeof (size_t) != total_write)
+    return adc->do_stop = 1;
   if (filename)
   {
-    total_write = wr = GNUNET_DISK_file_write (adc->progress_write,
-        filename, filename_len);
-    while (wr > 0 && total_write < filename_len)
+    total_write = 0;
+    wr = 1;
+    while ((wr > 0 || errno == EAGAIN) && total_write < filename_len)
     {
-      total_write = wr = GNUNET_DISK_file_write (adc->progress_write,
+      wr = GNUNET_DISK_file_write (adc->progress_write,
         &((char *)filename)[total_write], filename_len - total_write);
       if (wr > 0)
         total_write += wr;
     }
-    if (filename_len != wr)
-      return 1;
-    total_write = wr = GNUNET_DISK_file_write (adc->progress_write,
-      &is_directory, sizeof (char));
-    while (wr > 0 && total_write < sizeof (char))
+    if (filename_len != total_write)
+      return adc->do_stop = 1;
+    total_write = 0;
+    wr = 1;
+    while ((wr > 0 || errno == EAGAIN) && total_write < sizeof (char))
     {
-      total_write = wr = GNUNET_DISK_file_write (adc->progress_write,
+      wr = GNUNET_DISK_file_write (adc->progress_write,
         &((char *)&is_directory)[total_write], sizeof (char) - total_write);
       if (wr > 0)
         total_write += wr;
     }
-    if (sizeof (char) != wr)
-      return 1;
+    if (sizeof (char) != total_write)
+      return adc->do_stop = 1;
   }
   return 0;
 }

Modified: gnunet/src/util/disk.c
===================================================================
--- gnunet/src/util/disk.c      2012-01-14 16:04:58 UTC (rev 19139)
+++ gnunet/src/util/disk.c      2012-01-14 18:31:25 UTC (rev 19140)
@@ -718,15 +718,27 @@
   }
   else
   {
-    if (!ReadFile (h->h, result, len, NULL, h->oOverlapRead))
+#if DEBUG_PIPE
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "It is a pipe trying to read\n");
+#endif
+    if (!ReadFile (h->h, result, len, &bytesRead, h->oOverlapRead))
     {
       if (GetLastError () != ERROR_IO_PENDING)
       {
+#if DEBUG_PIPE
+        LOG (GNUNET_ERROR_TYPE_DEBUG, "Error reading from pipe: %u\n", 
GetLastError ());
+#endif
         SetErrnoFromWinError (GetLastError ());
         return GNUNET_SYSERR;
       }
+#if DEBUG_PIPE
+      LOG (GNUNET_ERROR_TYPE_DEBUG, "Will get overlapped result\n");
+#endif
+      GetOverlappedResult (h->h, h->oOverlapRead, &bytesRead, TRUE);
     }
-    GetOverlappedResult (h->h, h->oOverlapRead, &bytesRead, TRUE);
+#if DEBUG_PIPE
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "Read %u bytes\n", bytesRead);
+#endif
   }
   return bytesRead;
 #else
@@ -790,23 +802,67 @@
   else
   {
 #if DEBUG_PIPE
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "It is a pipe trying to write\n");
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "It is a pipe trying to write %u bytes\n", 
n);
 #endif
-    if (!WriteFile (h->h, buffer, n, NULL, h->oOverlapWrite))
+    if (!WriteFile (h->h, buffer, n, &bytesWritten, h->oOverlapWrite))
     {
       if (GetLastError () != ERROR_IO_PENDING)
       {
         SetErrnoFromWinError (GetLastError ());
 #if DEBUG_PIPE
-        LOG (GNUNET_ERROR_TYPE_DEBUG, "Error writing to pipe\n");
+        LOG (GNUNET_ERROR_TYPE_DEBUG, "Error writing to pipe: %u\n",
+            GetLastError ());
 #endif
         return GNUNET_SYSERR;
       }
+#if DEBUG_PIPE
+      LOG (GNUNET_ERROR_TYPE_DEBUG, "Will get overlapped result\n");
+#endif
+      if (!GetOverlappedResult (h->h, h->oOverlapWrite, &bytesWritten, TRUE))
+      {
+        SetErrnoFromWinError (GetLastError ());
+#if DEBUG_PIPE
+        LOG (GNUNET_ERROR_TYPE_DEBUG,
+            "Error getting overlapped result while writing to pipe: %u\n",
+            GetLastError ());
+#endif
+        return GNUNET_SYSERR;
+      }
     }
+    else
+    {
+      DWORD ovr;
+      if (!GetOverlappedResult (h->h, h->oOverlapWrite, &ovr, TRUE))
+      {
 #if DEBUG_PIPE
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "Will get overlapped result\n");
+        LOG (GNUNET_ERROR_TYPE_DEBUG,
+            "Error getting control overlapped result while writing to pipe: 
%u\n",
+            GetLastError ());
 #endif
-    GetOverlappedResult (h->h, h->oOverlapWrite, &bytesWritten, TRUE);
+      }
+      else
+      {
+#if DEBUG_PIPE
+        LOG (GNUNET_ERROR_TYPE_DEBUG,
+            "Wrote %u bytes (ovr says %u), picking the greatest\n",
+            bytesWritten, ovr);
+#endif
+      }
+    }
+    if (bytesWritten == 0)
+    {
+      if (n > 0)
+      {
+#if DEBUG_PIPE
+        LOG (GNUNET_ERROR_TYPE_DEBUG, "Wrote %u bytes, returning -1 with 
EAGAIN\n", bytesWritten);
+#endif
+        errno = EAGAIN;
+        return GNUNET_SYSERR;
+      }
+    }
+#if DEBUG_PIPE
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "Wrote %u bytes\n", bytesWritten);
+#endif
   }
   return bytesWritten;
 #else




reply via email to

[Prev in Thread] Current Thread [Next in Thread]