[prev in list] [next in list] [prev in thread] [next in thread] 

List:       apr-cvs
Subject:    svn commit: r512882 - in /apr/apr/trunk: file_io/os2/readwrite.c
From:       pquerna () apache ! org
Date:       2007-02-28 18:05:38
Message-ID: 20070228180538.A0CFA1A981C () eris ! apache ! org
[Download RAW message or body]

Author: pquerna
Date: Wed Feb 28 10:05:37 2007
New Revision: 512882

URL: http://svn.apache.org/viewvc?view=rev&rev=512882
Log:
Fix apr_file_writev when buffering is enabled by forcing a flush, rather than writing \
underneath the write buffer.

PR: 41197
Submitted By: Davi Arnaut

Modified:
    apr/apr/trunk/file_io/os2/readwrite.c
    apr/apr/trunk/file_io/unix/readwrite.c
    apr/apr/trunk/test/testfile.c

Modified: apr/apr/trunk/file_io/os2/readwrite.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/file_io/os2/readwrite.c?view=diff&rev=512882&r1=512881&r2=512882
 ==============================================================================
--- apr/apr/trunk/file_io/os2/readwrite.c (original)
+++ apr/apr/trunk/file_io/os2/readwrite.c Wed Feb 28 10:05:37 2007
@@ -197,6 +197,12 @@
 
 APR_DECLARE(apr_status_t) apr_file_writev(apr_file_t *thefile, const struct iovec \
*vec, apr_size_t nvec, apr_size_t *nbytes)  {
+    apr_status_t rv = apr_file_flush(thefile);
+
+    if (rv != APR_SUCCESS) {
+        return rv;
+    }
+
     int bytes;
     if ((bytes = writev(thefile->filedes, vec, nvec)) < 0) {
         *nbytes = 0;

Modified: apr/apr/trunk/file_io/unix/readwrite.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/file_io/unix/readwrite.c?view=diff&rev=512882&r1=512881&r2=512882
 ==============================================================================
--- apr/apr/trunk/file_io/unix/readwrite.c (original)
+++ apr/apr/trunk/file_io/unix/readwrite.c Wed Feb 28 10:05:37 2007
@@ -239,6 +239,12 @@
 APR_DECLARE(apr_status_t) apr_file_writev(apr_file_t *thefile, const struct iovec \
                *vec,
                                           apr_size_t nvec, apr_size_t *nbytes)
 {
+    apr_status_t rv = apr_file_flush(thefile);
+
+    if (rv != APR_SUCCESS) {
+        return rv;
+    }
+
 #ifdef HAVE_WRITEV
     apr_ssize_t bytes;
 

Modified: apr/apr/trunk/test/testfile.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/testfile.c?view=diff&rev=512882&r1=512881&r2=512882
 ==============================================================================
--- apr/apr/trunk/test/testfile.c (original)
+++ apr/apr/trunk/test/testfile.c Wed Feb 28 10:05:37 2007
@@ -661,6 +661,37 @@
 
 }
 
+static void test_writev_buffered(abts_case *tc, void *data)
+{
+    apr_file_t *f;
+    apr_size_t nbytes;
+    struct iovec vec[2];
+    const char *fname = "data/testwritev_buffered.txt";
+
+    APR_ASSERT_SUCCESS(tc, "open file for writing",
+                       apr_file_open(&f, fname,
+                                     APR_WRITE | APR_CREATE | APR_TRUNCATE |
+                                     APR_BUFFERED, APR_OS_DEFAULT, p));
+
+    nbytes = strlen(TESTSTR);
+    APR_ASSERT_SUCCESS(tc, "buffered write",
+                       apr_file_write(f, TESTSTR, &nbytes));
+
+    vec[0].iov_base = LINE1;
+    vec[0].iov_len = strlen(LINE1);
+    vec[1].iov_base = LINE2;
+    vec[1].iov_len = strlen(LINE2);
+
+    APR_ASSERT_SUCCESS(tc, "writev of size 2 to file",
+                       apr_file_writev(f, vec, 2, &nbytes));
+
+    APR_ASSERT_SUCCESS(tc, "close for writing",
+                       apr_file_close(f));
+
+    file_contents_equal(tc, fname, TESTSTR LINE1 LINE2,
+                        strlen(TESTSTR) + strlen(LINE1) + strlen(LINE2));
+}
+
 static void test_truncate(abts_case *tc, void *data)
 {
     apr_status_t rv;
@@ -885,6 +916,7 @@
     abts_run_test(suite, test_puts, NULL);
     abts_run_test(suite, test_writev, NULL);
     abts_run_test(suite, test_writev_full, NULL);
+    abts_run_test(suite, test_writev_buffered, NULL);
     abts_run_test(suite, test_bigread, NULL);
     abts_run_test(suite, test_mod_neg, NULL);
     abts_run_test(suite, test_truncate, NULL);


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic