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 <[email protected]> * io_stream.cc (copy): Propagate errors. Signed-off-by: Jon TURNEY <[email protected]> --- 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
