This is the mail archive of the cygwin-apps mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 3/6] Propagate errors out of io_stream::copy()


Despite the comment here, io_stream::read() is now implemented to provide the
same behaviour as POSIX read(): If the stream is at EOF, 0 is returned. If an
error occurred, -1 is returned.  So we can detect errors and propagate them to
our caller.

2011-04-08  Jon TURNEY  <jon.turney@dronecode.org.uk>

	* io_stream.cc (copy): Propagate errors.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
---
 io_stream.cc |   17 +++++++----------
 1 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/io_stream.cc b/io_stream.cc
index 08ecae4..49cf0c4 100644
--- a/io_stream.cc
+++ b/io_stream.cc
@@ -184,18 +184,15 @@ ssize_t io_stream::copy (io_stream * in, io_stream * out)
 	  return countout ? countout : -1;
 	}
     }
-  
-  /* Here it would be nice to be able to do something like
-
-       if (countin < 0)
-         return -1;
 
-     in order to be able to detect a read error occured and pass it on
-     to the caller, however with the current io_stream class this will fail
-     spectacularly because there is no way to signal an EOF condition, and
-     thus the only way the while loop above ends is the resulting error from
-     trying to read past EOF.
+  /*
+    Loop above ends with countin = 0 if we have reached EOF, or -1 if an
+    read error occurred.
+  */
+  if (countin < 0)
+    return -1;
 
+   /* Here it would be nice to be able to do something like
      TODO:
      out->set_mtime (in->get_mtime ());
    */
-- 
1.7.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]