about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2016-02-26T15·16+0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2016-02-26T15·16+0100
commit581e1bc5b45c7bbe227dbc5b35b60ca37efe059f (patch)
tree4cf2ed7ff0cc6eef1eb4b46fb206d59e0116a304
parentbcc9943cee4d4f62e0bceb4245d390fb60744eae (diff)
FdSource: track number of bytes read
-rw-r--r--src/libutil/serialise.cc3
-rw-r--r--src/libutil/serialise.hh10
2 files changed, 8 insertions, 5 deletions
diff --git a/src/libutil/serialise.cc b/src/libutil/serialise.cc
index c9620e2bf32a..a3cd4ff0d02c 100644
--- a/src/libutil/serialise.cc
+++ b/src/libutil/serialise.cc
@@ -64,9 +64,9 @@ static void warnLargeDump()
 
 void FdSink::write(const unsigned char * data, size_t len)
 {
+    written += len;
     static bool warned = false;
     if (warn && !warned) {
-        written += len;
         if (written > threshold) {
             warnLargeDump();
             warned = true;
@@ -131,6 +131,7 @@ size_t FdSource::readUnbuffered(unsigned char * data, size_t len)
     } while (n == -1 && errno == EINTR);
     if (n == -1) { _good = false; throw SysError("reading from file"); }
     if (n == 0) { _good = false; throw EndOfFile("unexpected end-of-file"); }
+    read += n;
     return n;
 }
 
diff --git a/src/libutil/serialise.hh b/src/libutil/serialise.hh
index 9e269f3923ea..0fdc4037b2d7 100644
--- a/src/libutil/serialise.hh
+++ b/src/libutil/serialise.hh
@@ -76,11 +76,11 @@ struct BufferedSource : Source
 struct FdSink : BufferedSink
 {
     int fd;
-    bool warn;
-    size_t written;
+    bool warn = false;
+    size_t written = 0;
 
-    FdSink() : fd(-1), warn(false), written(0) { }
-    FdSink(int fd) : fd(fd), warn(false), written(0) { }
+    FdSink() : fd(-1) { }
+    FdSink(int fd) : fd(fd) { }
     ~FdSink();
 
     void write(const unsigned char * data, size_t len) override;
@@ -96,6 +96,8 @@ private:
 struct FdSource : BufferedSource
 {
     int fd;
+    size_t read = 0;
+
     FdSource() : fd(-1) { }
     FdSource(int fd) : fd(fd) { }
     size_t readUnbuffered(unsigned char * data, size_t len) override;