Show More
@@ -78,13 +78,13 b' class client(object):' | |||||
78 | else: |
|
78 | else: | |
79 | raise |
|
79 | raise | |
80 |
|
80 | |||
81 | def _send(self, data): |
|
81 | def _send(self, type, data): | |
82 | """Sends protocol version number, and the data""" |
|
82 | """Sends protocol version number, and the data""" | |
83 | self.sock.sendall(chr(common.version) + data) |
|
83 | self.sock.sendall(chr(common.version) + type + data) | |
84 |
|
84 | |||
85 | self.sock.shutdown(socket.SHUT_WR) |
|
85 | self.sock.shutdown(socket.SHUT_WR) | |
86 |
|
86 | |||
87 | def _receive(self): |
|
87 | def _receive(self, type): | |
88 | """ |
|
88 | """ | |
89 | Read data, check version number, extract headers, |
|
89 | Read data, check version number, extract headers, | |
90 | and returns a tuple (data descriptor, header) |
|
90 | and returns a tuple (data descriptor, header) | |
@@ -97,8 +97,12 b' class client(object):' | |||||
97 | 'server version %d)\n') % version) |
|
97 | 'server version %d)\n') % version) | |
98 | raise QueryFailed('incompatible server version') |
|
98 | raise QueryFailed('incompatible server version') | |
99 |
|
99 | |||
100 | # only one type of request is supported for now |
|
100 | readtype = cs.read(4) | |
101 |
type |
|
101 | if readtype != type: | |
|
102 | self.ui.warn(_('(inotify: received \'%s\' response when expecting' | |||
|
103 | ' \'%s\')\n') % (readtype, type)) | |||
|
104 | raise QueryFailed('wrong response type') | |||
|
105 | ||||
102 | hdrfmt = common.resphdrfmts[type] |
|
106 | hdrfmt = common.resphdrfmts[type] | |
103 | hdrsize = common.resphdrsizes[type] |
|
107 | hdrsize = common.resphdrsizes[type] | |
104 | try: |
|
108 | try: | |
@@ -108,12 +112,12 b' class client(object):' | |||||
108 |
|
112 | |||
109 | return cs, resphdr |
|
113 | return cs, resphdr | |
110 |
|
114 | |||
111 | def query(self, req): |
|
115 | def query(self, type, req): | |
112 | self._connect() |
|
116 | self._connect() | |
113 |
|
117 | |||
114 | self._send(req) |
|
118 | self._send(type, req) | |
115 |
|
119 | |||
116 | return self._receive() |
|
120 | return self._receive(type) | |
117 |
|
121 | |||
118 | @start_server |
|
122 | @start_server | |
119 | def statusquery(self, names, match, ignored, clean, unknown=True): |
|
123 | def statusquery(self, names, match, ignored, clean, unknown=True): | |
@@ -130,7 +134,7 b' class client(object):' | |||||
130 |
|
134 | |||
131 | req = '\0'.join(genquery()) |
|
135 | req = '\0'.join(genquery()) | |
132 |
|
136 | |||
133 | cs, resphdr = self.query(req) |
|
137 | cs, resphdr = self.query('STAT', req) | |
134 |
|
138 | |||
135 | def readnames(nbytes): |
|
139 | def readnames(nbytes): | |
136 | if nbytes: |
|
140 | if nbytes: |
@@ -8,7 +8,27 b'' | |||||
8 |
|
8 | |||
9 | import cStringIO, socket, struct |
|
9 | import cStringIO, socket, struct | |
10 |
|
10 | |||
11 | version = 1 |
|
11 | """ | |
|
12 | Protocol between inotify clients and server: | |||
|
13 | ||||
|
14 | Client sending query: | |||
|
15 | 1) send protocol version number | |||
|
16 | 2) send query type (string, 4 letters long) | |||
|
17 | 3) send query parameters: | |||
|
18 | - For STAT, N+1 \0-separated strings: | |||
|
19 | 1) N different names that need checking | |||
|
20 | 2) 1 string containing all the status types to match | |||
|
21 | ||||
|
22 | Server sending query answer: | |||
|
23 | 1) send protocol version number | |||
|
24 | 2) send query type | |||
|
25 | 3) send struct.pack'ed headers describing the length of the content: | |||
|
26 | e.g. for STAT, receive 8 integers describing the length of the | |||
|
27 | 8 \0-separated string lists ( one list for each lmar!?ic status type ) | |||
|
28 | ||||
|
29 | """ | |||
|
30 | ||||
|
31 | version = 2 | |||
12 |
|
32 | |||
13 | resphdrfmts = { |
|
33 | resphdrfmts = { | |
14 | 'STAT': '>llllllll' # status requests |
|
34 | 'STAT': '>llllllll' # status requests |
@@ -594,6 +594,8 b' class server(object):' | |||||
594 | 'version %d\n') % version) |
|
594 | 'version %d\n') % version) | |
595 | return |
|
595 | return | |
596 |
|
596 | |||
|
597 | type = cs.read(4) | |||
|
598 | ||||
597 | names = cs.read().split('\0') |
|
599 | names = cs.read().split('\0') | |
598 |
|
600 | |||
599 | states = names.pop() |
|
601 | states = names.pop() | |
@@ -638,8 +640,8 b' class server(object):' | |||||
638 | try: |
|
640 | try: | |
639 | v = chr(common.version) |
|
641 | v = chr(common.version) | |
640 |
|
642 | |||
641 |
sock.sendall(v + struct.pack(common.resphdrfmts[ |
|
643 | sock.sendall(v + type + struct.pack(common.resphdrfmts[type], | |
642 | *map(len, results))) |
|
644 | *map(len, results))) | |
643 | sock.sendall(''.join(results)) |
|
645 | sock.sendall(''.join(results)) | |
644 | finally: |
|
646 | finally: | |
645 | sock.shutdown(socket.SHUT_WR) |
|
647 | sock.shutdown(socket.SHUT_WR) |
General Comments 0
You need to be logged in to leave comments.
Login now