gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r26979 - in gnunet/src: include util


From: gnunet
Subject: [GNUnet-SVN] r26979 - in gnunet/src: include util
Date: Tue, 23 Apr 2013 17:45:18 +0200

Author: harsha
Date: 2013-04-23 17:45:18 +0200 (Tue, 23 Apr 2013)
New Revision: 26979

Modified:
   gnunet/src/include/gnunet_bio_lib.h
   gnunet/src/util/bio.c
Log:
- Support flushing of buffered data


Modified: gnunet/src/include/gnunet_bio_lib.h
===================================================================
--- gnunet/src/include/gnunet_bio_lib.h 2013-04-23 15:30:49 UTC (rev 26978)
+++ gnunet/src/include/gnunet_bio_lib.h 2013-04-23 15:45:18 UTC (rev 26979)
@@ -225,6 +225,17 @@
 
 
 /**
+ * Force a buffered writer to flush its buffer
+ *
+ * @param h the writer handle
+ * @return GNUNET_OK upon success.  Upon failure GNUNET_SYSERR is returned and
+ *           the file is closed
+ */
+int
+GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h);
+
+
+/**
  * Write a string to a file.
  *
  * @param h handle to open file

Modified: gnunet/src/util/bio.c
===================================================================
--- gnunet/src/util/bio.c       2013-04-23 15:30:49 UTC (rev 26978)
+++ gnunet/src/util/bio.c       2013-04-23 15:45:18 UTC (rev 26979)
@@ -349,7 +349,6 @@
   h->buffer = (char *) &h[1];
   h->size = BIO_BUFFER_SIZE;
   h->fd = fd;
-
   return h;
 }
 
@@ -363,28 +362,41 @@
 int
 GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h)
 {
-  ssize_t wrt;
   int ret;
 
-  if (NULL == h->fd)
-  {
-    ret = GNUNET_SYSERR;
-  }
-  else
-  {
-    wrt = GNUNET_DISK_file_write (h->fd, h->buffer, h->have);
-    if (wrt == h->have)
-      ret = GNUNET_OK;
-    else
-      ret = GNUNET_SYSERR;
+  ret = GNUNET_SYSERR;
+  if ( (NULL != h->fd) && (GNUNET_OK == (ret = GNUNET_BIO_flush (h))) )
     GNUNET_DISK_file_close (h->fd);
-  }
   GNUNET_free (h);
   return ret;
 }
 
 
 /**
+ * Force a buffered writer to flush its buffer
+ *
+ * @param h the writer handle
+ * @return GNUNET_OK upon success.  Upon failure GNUNET_SYSERR is returned and
+ *           the file is closed
+ */
+int
+GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h)
+{
+  ssize_t ret;
+
+  ret = GNUNET_DISK_file_write (h->fd, h->buffer, h->have);
+  if (ret != h->have)
+  {
+    GNUNET_DISK_file_close (h->fd);
+    h->fd = NULL;
+    return GNUNET_SYSERR;     /* error */
+  }
+  h->have = 0;
+  return GNUNET_OK;
+}
+
+
+/**
  * Write a buffer to a file.
  *
  * @param h handle to open file
@@ -399,7 +411,6 @@
   const char *src = buffer;
   size_t min;
   size_t pos;
-  ssize_t ret;
 
   if (NULL == h->fd)
     return GNUNET_SYSERR;
@@ -416,14 +427,8 @@
     if (pos == n)
       return GNUNET_OK;         /* done */
     GNUNET_assert (h->have == h->size);
-    ret = GNUNET_DISK_file_write (h->fd, h->buffer, h->size);
-    if (ret != h->size)
-    {
-      GNUNET_DISK_file_close (h->fd);
-      h->fd = NULL;
+    if (GNUNET_OK != GNUNET_BIO_flush (h))
       return GNUNET_SYSERR;     /* error */
-    }
-    h->have = 0;
   }
   while (pos < n);              /* should always be true */
   GNUNET_break (0);




reply via email to

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