about summary refs log tree commit diff
path: root/src/libutil/serialise.hh
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2011-12-15T12·32+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2011-12-15T12·32+0000
commita3e0656cbbfadba28518e0a29c324edaabb9874a (patch)
tree026d7097aed0755d3de2eca9e500b504f20b7410 /src/libutil/serialise.hh
parent3a48282b0681d68147e18f7464eaddf1d188c3be (diff)
* Buffer reads in FdSource. Together with write buffering, this
  significantly cuts down the number of syscalls (e.g., for "nix-store
  -qR /var/run/current-system" via the daemon, it reduced the number
  of syscalls in the client from 29134 to 4766 and in the daemon from
  44266 to 20666).

Diffstat (limited to 'src/libutil/serialise.hh')
-rw-r--r--src/libutil/serialise.hh18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/libutil/serialise.hh b/src/libutil/serialise.hh
index 711bd5e6c7ce..b8d4d7a849d2 100644
--- a/src/libutil/serialise.hh
+++ b/src/libutil/serialise.hh
@@ -38,9 +38,7 @@ struct FdSink : Sink
     FdSink() : fd(-1), bufSize(32 * 1024), bufPos(0), buffer(0) { }
     
     FdSink(int fd, unsigned int bufSize = 32 * 1024)
-        : fd(fd), bufSize(bufSize), bufPos(0), buffer(0)
-    {
-    }
+        : fd(fd), bufSize(bufSize), bufPos(0), buffer(0) { }
 
     ~FdSink()
     {
@@ -58,15 +56,17 @@ struct FdSink : Sink
 struct FdSource : Source
 {
     int fd;
+    unsigned int bufSize, bufPosIn, bufPosOut;
+    unsigned char * buffer;
 
-    FdSource()
-    {
-        fd = -1;
-    }
+    FdSource() : fd(-1), bufSize(32 * 1024), bufPosIn(0), bufPosOut(0), buffer(0) { }
+    
+    FdSource(int fd, unsigned int bufSize = 32 * 1024)
+        : fd(fd), bufSize(bufSize), bufPosIn(0), bufPosOut(0), buffer(0) { }
     
-    FdSource(int fd) 
+    ~FdSource()
     {
-        this->fd = fd;
+        if (buffer) delete[] buffer;
     }
     
     void operator () (unsigned char * data, unsigned int len);