diff options
author | eldritch horrors <pennae@lix.systems> | 2024-04-05 23:17:18 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@lix> | 2024-04-05 23:17:18 +0000 |
commit | e9e1b6963c8ee2a0a382487e1346677e77bc1e9e (patch) | |
tree | 4d63978643543657db594327a8f70e1b5c3931d2 /src/libutil/serialise.cc | |
parent | 405e41e288768ed99002f7b1d7d68f41c6152c12 (diff) | |
parent | 38dc6f5b69da81dfd21780ef16efaa297f9c2231 (diff) |
Merge changes I1fa30114,I3ca208b6,Ide4c6e00,I74c46b9f,I05fa6a9d, ... into main
* changes:
Revert "libutil: drop Pool resources on exceptional free"
Revert "libutil: remove Pool::Handle::bad"
Revert "libstore: remove one Resource::good flag"
Revert "libstore: using throwing finally in withFramedSink"
Revert "libutil: allow graceful dropping of Pool::Handle"
Revert "libutil: drop Fs{Source,Sink}::good"
libutil: guard Finally against invalid exception throws
Diffstat (limited to 'src/libutil/serialise.cc')
-rw-r--r-- | src/libutil/serialise.cc | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/libutil/serialise.cc b/src/libutil/serialise.cc index 6450a9651..692144b75 100644 --- a/src/libutil/serialise.cc +++ b/src/libutil/serialise.cc @@ -52,7 +52,18 @@ FdSink::~FdSink() void FdSink::writeUnbuffered(std::string_view data) { written += data.size(); - writeFull(fd, data); + try { + writeFull(fd, data); + } catch (SysError & e) { + _good = false; + throw; + } +} + + +bool FdSink::good() +{ + return _good; } @@ -117,13 +128,19 @@ size_t FdSource::readUnbuffered(char * data, size_t len) checkInterrupt(); n = ::read(fd, data, len); } while (n == -1 && errno == EINTR); - if (n == -1) { throw SysError("reading from file"); } - if (n == 0) { throw EndOfFile(std::string(*endOfFileError)); } + if (n == -1) { _good = false; throw SysError("reading from file"); } + if (n == 0) { _good = false; throw EndOfFile(std::string(*endOfFileError)); } read += n; return n; } +bool FdSource::good() +{ + return _good; +} + + size_t StringSource::read(char * data, size_t len) { if (pos == s.size()) throw EndOfFile("end of string reached"); |