apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s.@apache.org
Subject svn commit: r1073142 - in /apr/apr/trunk: CHANGES file_io/unix/readwrite.c
Date Mon, 21 Feb 2011 21:23:37 GMT
Author: sf
Date: Mon Feb 21 21:23:36 2011
New Revision: 1073142

URL: http://svn.apache.org/viewvc?rev=1073142&view=rev
Log:
apr_file_flush_locked(): Handle short writes

Modified:
    apr/apr/trunk/CHANGES
    apr/apr/trunk/file_io/unix/readwrite.c

Modified: apr/apr/trunk/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/trunk/CHANGES?rev=1073142&r1=1073141&r2=1073142&view=diff
==============================================================================
--- apr/apr/trunk/CHANGES [utf-8] (original)
+++ apr/apr/trunk/CHANGES [utf-8] Mon Feb 21 21:23:36 2011
@@ -1,6 +1,8 @@
                                                      -*- coding: utf-8 -*-
 Changes for APR 2.0.0
 
+  *) apr_file_flush_locked(): Handle short writes. [Stefan Fritsch]
+
   *) Add new configure option --enable-allocator-uses-mmap to use mmap
      instead of malloc in apr_allocator_alloc(). This greatly reduces
      memory fragmentation with malloc implementations (e.g. glibc) that

Modified: apr/apr/trunk/file_io/unix/readwrite.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/file_io/unix/readwrite.c?rev=1073142&r1=1073141&r2=1073142&view=diff
==============================================================================
--- apr/apr/trunk/file_io/unix/readwrite.c (original)
+++ apr/apr/trunk/file_io/unix/readwrite.c Mon Feb 21 21:23:36 2011
@@ -400,12 +400,16 @@ apr_status_t apr_file_flush_locked(apr_f
     apr_status_t rv = APR_SUCCESS;
 
     if (thefile->direction == 1 && thefile->bufpos) {
-        apr_ssize_t written;
+        apr_ssize_t written = 0, ret;
 
         do {
-            written = write(thefile->filedes, thefile->buffer, thefile->bufpos);
-        } while (written == -1 && errno == EINTR);
-        if (written == -1) {
+            ret = write(thefile->filedes, thefile->buffer + written,
+                        thefile->bufpos - written);
+            if (ret > 0)
+                written += ret;
+        } while (written < thefile->bufpos &&
+                 (ret > 0 || (ret == -1 && errno == EINTR)));
+        if (ret == -1) {
             rv = errno;
         } else {
             thefile->filePtr += written;



Mime
View raw message