You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by jo...@apache.org on 2005/08/22 21:13:05 UTC
svn commit: r239221 - in /apr/apr/trunk: CHANGES file_io/unix/readwrite.c
test/testfile.c
Author: jorton
Date: Mon Aug 22 12:12:59 2005
New Revision: 239221
URL: http://svn.apache.org/viewcvs?rev=239221&view=rev
Log:
* file_io/unix/readwrite.c (apr_file_read, apr_file_gets): Handle the
apr_file_flush() return value when flushing buffered writes.
* test/testfile.c (test_fail_read_flush): Add test case.
Modified:
apr/apr/trunk/CHANGES
apr/apr/trunk/file_io/unix/readwrite.c
apr/apr/trunk/test/testfile.c
Modified: apr/apr/trunk/CHANGES
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/CHANGES?rev=239221&r1=239220&r2=239221&view=diff
==============================================================================
--- apr/apr/trunk/CHANGES (original)
+++ apr/apr/trunk/CHANGES Mon Aug 22 12:12:59 2005
@@ -1,5 +1,8 @@
Changes for APR 1.3.0
+ *) Fix apr_file_gets() and apr_file_read() to catch write failures
+ when flushing pending writes for a buffered file. [Joe Orton]
+
*) Fix apr_file_write() infinite loop on write failure for buffered
files. [Erik Huelsmann <ehuels gmail.com>]
Modified: apr/apr/trunk/file_io/unix/readwrite.c
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/file_io/unix/readwrite.c?rev=239221&r1=239220&r2=239221&view=diff
==============================================================================
--- apr/apr/trunk/file_io/unix/readwrite.c (original)
+++ apr/apr/trunk/file_io/unix/readwrite.c Mon Aug 22 12:12:59 2005
@@ -47,7 +47,15 @@
#endif
if (thefile->direction == 1) {
- apr_file_flush(thefile);
+ rv = apr_file_flush(thefile);
+ if (rv) {
+#if APR_HAS_THREADS
+ if (thefile->thlock) {
+ apr_thread_mutex_unlock(thefile->thlock);
+ }
+#endif
+ return rv;
+ }
thefile->bufpos = 0;
thefile->direction = 0;
thefile->dataRead = 0;
@@ -333,7 +341,16 @@
#endif
if (thefile->direction == 1) {
- apr_file_flush(thefile);
+ rv = apr_file_flush(thefile);
+ if (rv) {
+#if APR_HAS_THREADS
+ if (thefile->thlock) {
+ apr_thread_mutex_unlock(thefile->thlock);
+ }
+#endif
+ return rv;
+ }
+
thefile->direction = 0;
thefile->bufpos = 0;
thefile->dataRead = 0;
Modified: apr/apr/trunk/test/testfile.c
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/test/testfile.c?rev=239221&r1=239220&r2=239221&view=diff
==============================================================================
--- apr/apr/trunk/test/testfile.c (original)
+++ apr/apr/trunk/test/testfile.c Mon Aug 22 12:12:59 2005
@@ -734,6 +734,42 @@
apr_file_close(f);
}
+static void test_fail_read_flush(abts_case *tc, void *data)
+{
+ apr_file_t *f;
+ const char *fname = "data/testflush.dat";
+ apr_status_t rv;
+ char buf[2];
+
+ apr_file_remove(fname, p);
+
+ APR_ASSERT_SUCCESS(tc, "open test file",
+ apr_file_open(&f, fname,
+ APR_CREATE|APR_READ|APR_BUFFERED,
+ APR_UREAD|APR_UWRITE, p));
+
+ /* this write should be buffered. */
+ APR_ASSERT_SUCCESS(tc, "buffered write should succeed",
+ apr_file_puts("hello", f));
+
+ /* Now, trying a read should fail since the write must be flushed,
+ * and should fail with something other than EOF since the file is
+ * opened read-only. */
+ rv = apr_file_read_full(f, buf, 2, NULL);
+
+ ABTS_ASSERT(tc, "read should flush buffered write and fail",
+ rv != APR_SUCCESS && rv != APR_EOF);
+
+ /* Likewise for gets */
+ rv = apr_file_gets(buf, 2, f);
+
+ ABTS_ASSERT(tc, "gets should flush buffered write and fail",
+ rv != APR_SUCCESS && rv != APR_EOF);
+
+ apr_file_close(f);
+}
+
+
abts_suite *testfile(abts_suite *suite)
{
suite = ADD_SUITE(suite)
@@ -765,6 +801,7 @@
abts_run_test(suite, test_truncate, NULL);
abts_run_test(suite, test_bigfprintf, NULL);
abts_run_test(suite, test_fail_write_flush, NULL);
+ abts_run_test(suite, test_fail_read_flush, NULL);
return suite;
}