gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r19149 - gnunet/src/util


From: gnunet
Subject: [GNUnet-SVN] r19149 - gnunet/src/util
Date: Sun, 15 Jan 2012 00:26:53 +0100

Author: grothoff
Date: 2012-01-15 00:26:53 +0100 (Sun, 15 Jan 2012)
New Revision: 19149

Modified:
   gnunet/src/util/disk.c
Log:
-implement blocking write / non-blocking read for non-W32 systems

Modified: gnunet/src/util/disk.c
===================================================================
--- gnunet/src/util/disk.c      2012-01-14 23:18:52 UTC (rev 19148)
+++ gnunet/src/util/disk.c      2012-01-14 23:26:53 UTC (rev 19149)
@@ -115,7 +115,7 @@
 };
 
 
-int
+static int
 translate_unix_perms (enum GNUNET_DISK_AccessPermissions perm)
 {
   int mode;
@@ -420,6 +420,7 @@
   fn = tmpl;
 #endif
   /* FIXME: why is this not MKSTEMP()? This function is implemented in plibc.
+   * CG: really? If I put MKSTEMP here, I get a compilation error...
    * It will assume that fn is UTF-8-encoded, if compiled with UTF-8 support.
    */
   fd = mkstemp (fn);
@@ -531,6 +532,7 @@
   return GNUNET_YES;
 }
 
+
 /**
  * Check that fil corresponds to a filename
  * (of a file that exists and that is not a directory).
@@ -746,6 +748,7 @@
 #endif
 }
 
+
 /**
  * Read the contents of a binary file into a buffer.
  * Guarantees not to block (returns GNUNET_SYSERR and sets errno to EAGAIN
@@ -809,8 +812,17 @@
   }
   return bytesRead;
 #else
-  /* FIXME: set to non-blocking (fcntl?), read, then set back? */
-  return read (h->fd, result, len);
+  int flags;
+  ssize_t ret;
+
+  /* set to non-blocking, read, then set back */
+  flags = fcntl (h->fd, F_GETFL);
+  if (0 == (flags & O_NONBLOCK))
+    fcntl (h->fd, F_SETFL, flags | O_NONBLOCK);
+  ret = read (h->fd, result, len);
+  if (0 == (flags & O_NONBLOCK))
+    fcntl (h->fd, F_SETFL, flags);
+  return ret;
 #endif
 }
 
@@ -938,6 +950,7 @@
 #endif
 }
 
+
 /**
  * Write a buffer to a file, blocking, if necessary.
  * @param h handle to open file
@@ -991,11 +1004,21 @@
 #endif
   return bytesWritten;
 #else
-  /* FIXME: switch to blocking mode (fcntl?), write, then switch back? */
-  return write (h->fd, buffer, n);
+  int flags;
+  ssize_t ret;
+
+  /* set to blocking, write, then set back */
+  flags = fcntl (h->fd, F_GETFL);
+  if (0 != (flags & O_NONBLOCK))
+    fcntl (h->fd, F_SETFL, flags - O_NONBLOCK);
+  ret = write (h->fd, buffer, n);
+  if (0 == (flags & O_NONBLOCK))
+    fcntl (h->fd, F_SETFL, flags);
+  return ret;
 #endif
 }
 
+
 /**
  * Write a buffer to a file.  If the file is longer than the
  * number of bytes that will be written, it will be truncated.




reply via email to

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