File tree Expand file tree Collapse file tree 4 files changed +63
-7
lines changed Expand file tree Collapse file tree 4 files changed +63
-7
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,8 @@ libstore_la_SOURCES = \
6
6
7
7
pkginclude_HEADERS = \
8
8
store-api.hh local-store.cc remote-store.cc derivations.hh misc.hh \
9
- globals.hh db.hh references.hh pathlocks.hh gc.hh
9
+ globals.hh db.hh references.hh pathlocks.hh gc.hh \
10
+ worker-protocol.hh
10
11
11
12
libstore_la_LIBADD = ../libutil/libutil.la ../boost/format/libformat.la
12
13
Original file line number Diff line number Diff line change 1
1
#include " serialise.hh"
2
2
#include " util.hh"
3
3
#include " remote-store.hh"
4
+ #include " worker-protocol.hh"
4
5
5
6
#include < iostream>
6
7
#include < unistd.h>
@@ -55,27 +56,36 @@ RemoteStore::RemoteStore()
55
56
56
57
57
58
/* Send the magic greeting, check for the reply. */
58
- writeInt (0x6e697864 , to);
59
+ writeInt (WORKER_MAGIC_1 , to);
59
60
60
61
unsigned int magic = readInt (from);
61
- if (magic != 0x6478696e ) throw Error (" protocol mismatch" );
62
+ if (magic != WORKER_MAGIC_2 ) throw Error (" protocol mismatch" );
62
63
}
63
64
64
65
65
66
RemoteStore::~RemoteStore ()
66
67
{
68
+ writeInt (wopQuit, to);
69
+ readInt (from);
70
+ child.wait (true );
67
71
}
68
72
69
73
70
74
bool RemoteStore::isValidPath (const Path & path)
71
75
{
72
- throw Error (" not implemented" );
76
+ writeInt (wopIsValidPath, to);
77
+ writeString (path, to);
78
+ unsigned int reply = readInt (from);
79
+ return reply != 0 ;
73
80
}
74
81
75
82
76
83
Substitutes RemoteStore::querySubstitutes (const Path & srcPath)
77
84
{
78
- throw Error (" not implemented" );
85
+ // writeInt(wopQuerySubstitutes);
86
+
87
+ // throw Error("not implemented 2");
88
+ return Substitutes ();
79
89
}
80
90
81
91
Original file line number Diff line number Diff line change
1
+ #ifndef __WORKER_PROTOCOL_H
2
+ #define __WORKER_PROTOCOL_H
3
+
4
+
5
+ #define WORKER_MAGIC_1 0x6e697864
6
+ #define WORKER_MAGIC_2 0x6478696e
7
+
8
+
9
+ typedef enum {
10
+ wopQuit = 0 ,
11
+ wopIsValidPath = 1 ,
12
+ wopQuerySubstitutes = 2 ,
13
+ } WorkerOp;
14
+
15
+
16
+ #endif /* !__WORKER_PROTOCOL_H */
Original file line number Diff line number Diff line change 2
2
#include " local-store.hh"
3
3
#include " util.hh"
4
4
#include " serialise.hh"
5
+ #include " worker-protocol.hh"
5
6
6
7
using namespace nix ;
7
8
@@ -11,11 +12,39 @@ void processConnection(Source & from, Sink & to)
11
12
store = boost::shared_ptr<StoreAPI>(new LocalStore (true ));
12
13
13
14
unsigned int magic = readInt (from);
14
- if (magic != 0x6e697864 ) throw Error (" protocol mismatch" );
15
+ if (magic != WORKER_MAGIC_1 ) throw Error (" protocol mismatch" );
15
16
16
- writeInt (0x6478696e , to);
17
+ writeInt (WORKER_MAGIC_2 , to);
17
18
18
19
debug (" greeting exchanged" );
20
+
21
+ bool quit = false ;
22
+
23
+ do {
24
+
25
+ WorkerOp op = (WorkerOp) readInt (from);
26
+
27
+ switch (op) {
28
+
29
+ case wopQuit:
30
+ /* Close the database. */
31
+ store.reset ((StoreAPI *) 0 );
32
+ writeInt (1 , to);
33
+ quit = true ;
34
+ break ;
35
+
36
+ case wopIsValidPath: {
37
+ Path path = readString (from);
38
+ assertStorePath (path);
39
+ writeInt (store->isValidPath (path), to);
40
+ break ;
41
+ }
42
+
43
+ default :
44
+ throw Error (" invalid operation" );
45
+ }
46
+
47
+ } while (!quit);
19
48
}
20
49
21
50
You can’t perform that action at this time.
0 commit comments