1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:17:35 +00:00

Streams: Consistent behaviour when reading from stream with error.

The streaming operator doesn't short-circuit, consider the following
snippet:

    void foo(InputStream& stream) {
        int a, b;
        stream >> a >> b;
    }

If the first read fails, the second is called regardless. It should be
well defined what happens in this case: nothing.
This commit is contained in:
asynts 2020-09-05 16:39:56 +02:00 committed by Andreas Kling
parent 5d85be7ed4
commit 6de63782c7
8 changed files with 24 additions and 3 deletions

View file

@ -75,6 +75,7 @@ namespace AK {
class InputStream : public virtual AK::Detail::Stream {
public:
// Does nothing and returns zero if there is already an error.
virtual size_t read(Bytes) = 0;
virtual bool read_or_error(Bytes) = 0;
virtual bool eof() const = 0;