aboutsummaryrefslogtreecommitdiff
path: root/src/nix-worker/main.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix-worker/main.cc')
-rw-r--r--src/nix-worker/main.cc33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/nix-worker/main.cc b/src/nix-worker/main.cc
index f71b604d0..d6966c2bf 100644
--- a/src/nix-worker/main.cc
+++ b/src/nix-worker/main.cc
@@ -2,6 +2,7 @@
#include "local-store.hh"
#include "util.hh"
#include "serialise.hh"
+#include "worker-protocol.hh"
using namespace nix;
@@ -11,11 +12,39 @@ void processConnection(Source & from, Sink & to)
store = boost::shared_ptr<StoreAPI>(new LocalStore(true));
unsigned int magic = readInt(from);
- if (magic != 0x6e697864) throw Error("protocol mismatch");
+ if (magic != WORKER_MAGIC_1) throw Error("protocol mismatch");
- writeInt(0x6478696e, to);
+ writeInt(WORKER_MAGIC_2, to);
debug("greeting exchanged");
+
+ bool quit = false;
+
+ do {
+
+ WorkerOp op = (WorkerOp) readInt(from);
+
+ switch (op) {
+
+ case wopQuit:
+ /* Close the database. */
+ store.reset((StoreAPI *) 0);
+ writeInt(1, to);
+ quit = true;
+ break;
+
+ case wopIsValidPath: {
+ Path path = readString(from);
+ assertStorePath(path);
+ writeInt(store->isValidPath(path), to);
+ break;
+ }
+
+ default:
+ throw Error("invalid operation");
+ }
+
+ } while (!quit);
}