]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2369] Distinguish between EOF and failures in getChar()
authorMukund Sivaraman <muks@isc.org>
Thu, 1 Nov 2012 05:05:17 +0000 (10:35 +0530)
committerMukund Sivaraman <muks@isc.org>
Thu, 1 Nov 2012 05:05:17 +0000 (10:35 +0530)
src/lib/dns/master_lexer_inputsource.cc
src/lib/dns/master_lexer_inputsource.h

index a871f3c28762746993219132effede828470b194..a747dfbfc4aa35149ba743b898211582ec5099d8 100644 (file)
@@ -70,10 +70,16 @@ InputSource::getChar() {
         // Have we reached EOF now? If so, set at_eof_ and return early,
         // but don't modify buffer_pos_ (which should still be equal to
         // the size of buffer_).
-        if (!input_.good()) {
+        if (input_.eof()) {
             at_eof_ = true;
             return (END_OF_STREAM);
         }
+        // This has to come after the .eof() check as some
+        // implementations seem to check the eofbit also in .fail().
+        if (input_.fail()) {
+            isc_throw(ReadError,
+                      "Error reading from the input stream: " << getName());
+        }
         buffer_.push_back(c);
     }
 
index 46e614705723fef51d7d38c59c8d5e704d8fe509..aec53950c6694f0fc15d6c41fd158cc81f2f84c2 100644 (file)
@@ -79,11 +79,22 @@ public:
         {}
     };
 
+    /// \brief Exception thrown when we fail to read from the input
+    /// stream or file.
+    struct ReadError : public Unexpected {
+        ReadError(const char* file, size_t line, const char* what) :
+            Unexpected(file, line, what)
+        {}
+    };
+
     /// \brief Returned by getChar() when end of stream is reached.
     static const int END_OF_STREAM;
 
     /// \brief Returns a single character from the input source. If end
     /// of file is reached, \c END_OF_STREAM is returned.
+    ///
+    /// \throws ReadError when reading from the input stream or file
+    /// fails.
     int getChar();
 
     /// \brief Skips backward a single character in the input