apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Davi Arnaut <d...@haxent.com.br>
Subject [patch 6/9] writev_full fallback
Date Fri, 27 Apr 2007 14:29:24 GMT
Rework apr_file_writev_full so it tries to writev() data before resorting to
a plain write.

---
 srclib/apr/file_io/unix/fullrw.c |   32 +++++++++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)

Index: 2.2.x/srclib/apr/file_io/unix/fullrw.c
===================================================================
--- 2.2.x.orig/srclib/apr/file_io/unix/fullrw.c	2007-04-27 11:09:48.000000000 -0300
+++ 2.2.x/srclib/apr/file_io/unix/fullrw.c	2007-04-27 11:09:51.000000000 -0300
@@ -72,10 +72,36 @@
     apr_size_t amt = 0;
     apr_size_t total = 0;
 
-    for (i = 0; i < nvec && rv == APR_SUCCESS; i++) {
-        rv = apr_file_write_full(thefile, vec[i].iov_base, 
+    for (i = 0; i < nvec; i++) {
+        total += vec[i].iov_len;
+    }
+
+    rv = apr_file_writev(thefile, vec, nvec, &amt);
+
+    if (bytes_written != NULL)
+        *bytes_written = amt;
+
+    if (rv != APR_SUCCESS || (amt == total)) {
+        return rv;
+    }
+
+    for (i = 0; i < nvec && amt; i++) {
+        if (amt >= vec[i].iov_len) {
+            amt -= vec[i].iov_len;
+        }
+        else {
+            break;
+        }
+    }
+
+    if (amt) {
+        rv = apr_file_write_full(thefile, vec[i].iov_base + amt,
+                                 vec[i].iov_len - amt, NULL);
+    }
+
+    for (; i < nvec && rv == APR_SUCCESS; i++) {
+        rv = apr_file_write_full(thefile, vec[i].iov_base,
                                  vec[i].iov_len, &amt);
-        total += amt;
     }
 
     if (bytes_written != NULL)

--

Mime
View raw message