about summary refs log tree commit diff
path: root/src/libstore
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2016-02-23T15·40+0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2016-02-23T15·40+0100
commitd5626bf4c14f725136f2c5b6ac8bf818627352f0 (patch)
treea8fde81ecedfd2f8ba640e07bf6ea1bb0564c438 /src/libstore
parente292144d46e3fbb24ee9ee67f1682b268373921b (diff)
Pool<T>: Allow a maximum pool size
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/remote-store.cc30
-rw-r--r--src/libstore/remote-store.hh7
2 files changed, 19 insertions, 18 deletions
diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc
index 847da107a111..f6ec3fffb614 100644
--- a/src/libstore/remote-store.cc
+++ b/src/libstore/remote-store.cc
@@ -14,8 +14,8 @@
 #include <sys/un.h>
 #include <errno.h>
 #include <fcntl.h>
-
 #include <unistd.h>
+
 #include <cstring>
 
 namespace nix {
@@ -39,8 +39,8 @@ template<class T> T readStorePaths(Source & from)
 template PathSet readStorePaths(Source & from);
 
 
-RemoteStore::RemoteStore()
-    : connections(make_ref<Pool<Connection>>([this]() { return openConnection(); }))
+RemoteStore::RemoteStore(size_t maxConnections)
+    : connections(make_ref<Pool<Connection>>(maxConnections, [this]() { return openConnection(); }))
 {
 }
 
@@ -116,18 +116,6 @@ ref<RemoteStore::Connection> RemoteStore::openConnection(bool reserveSpace)
 }
 
 
-RemoteStore::~RemoteStore()
-{
-    try {
-        //to.flush();
-        //fdSocket.close();
-        // FIXME: close pool
-    } catch (...) {
-        ignoreException();
-    }
-}
-
-
 void RemoteStore::setOptions(ref<Connection> conn)
 {
     conn->to << wopSetOptions
@@ -568,6 +556,18 @@ bool RemoteStore::verifyStore(bool checkContents, bool repair)
     return readInt(conn->from) != 0;
 }
 
+
+RemoteStore::Connection::~Connection()
+{
+    try {
+        to.flush();
+        fd.close();
+    } catch (...) {
+        ignoreException();
+    }
+}
+
+
 void RemoteStore::Connection::processStderr(Sink * sink, Source * source)
 {
     to.flush();
diff --git a/src/libstore/remote-store.hh b/src/libstore/remote-store.hh
index b16a6b51db0f..af417b84ff9c 100644
--- a/src/libstore/remote-store.hh
+++ b/src/libstore/remote-store.hh
@@ -1,5 +1,6 @@
 #pragma once
 
+#include <limits>
 #include <string>
 
 #include "store-api.hh"
@@ -19,9 +20,7 @@ class RemoteStore : public Store
 {
 public:
 
-    RemoteStore();
-
-    ~RemoteStore();
+    RemoteStore(size_t maxConnections = std::numeric_limits<size_t>::max());
 
     /* Implementations of abstract store API methods. */
 
@@ -100,6 +99,8 @@ private:
         FdSource from;
         unsigned int daemonVersion;
 
+        ~Connection();
+
         void processStderr(Sink * sink = 0, Source * source = 0);
     };