author | Nicolas Dumazet <nicdumz.commits@gmail.com> |
Fri, 17 Apr 2009 20:10:47 +0900 | |
changeset 8553 | e387ecd7a6ed |
parent 8386 | 4aad982111b6 |
child 8555 | 3e09bc5fee12 |
permissions | -rw-r--r-- |
6239 | 1 |
# server.py - inotify common protocol code |
2 |
# |
|
3 |
# Copyright 2006, 2007, 2008 Bryan O'Sullivan <bos@serpentine.com> |
|
4 |
# Copyright 2007, 2008 Brendan Cully <brendan@kublai.com> |
|
5 |
# |
|
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
6239
diff
changeset
|
6 |
# This software may be used and distributed according to the terms of the |
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
6239
diff
changeset
|
7 |
# GNU General Public License version 2, incorporated herein by reference. |
6239 | 8 |
|
9 |
import cStringIO, socket, struct |
|
10 |
||
8553
e387ecd7a6ed
inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8386
diff
changeset
|
11 |
""" |
e387ecd7a6ed
inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8386
diff
changeset
|
12 |
Protocol between inotify clients and server: |
e387ecd7a6ed
inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8386
diff
changeset
|
13 |
|
e387ecd7a6ed
inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8386
diff
changeset
|
14 |
Client sending query: |
e387ecd7a6ed
inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8386
diff
changeset
|
15 |
1) send protocol version number |
e387ecd7a6ed
inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8386
diff
changeset
|
16 |
2) send query type (string, 4 letters long) |
e387ecd7a6ed
inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8386
diff
changeset
|
17 |
3) send query parameters: |
e387ecd7a6ed
inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8386
diff
changeset
|
18 |
- For STAT, N+1 \0-separated strings: |
e387ecd7a6ed
inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8386
diff
changeset
|
19 |
1) N different names that need checking |
e387ecd7a6ed
inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8386
diff
changeset
|
20 |
2) 1 string containing all the status types to match |
e387ecd7a6ed
inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8386
diff
changeset
|
21 |
|
e387ecd7a6ed
inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8386
diff
changeset
|
22 |
Server sending query answer: |
e387ecd7a6ed
inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8386
diff
changeset
|
23 |
1) send protocol version number |
e387ecd7a6ed
inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8386
diff
changeset
|
24 |
2) send query type |
e387ecd7a6ed
inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8386
diff
changeset
|
25 |
3) send struct.pack'ed headers describing the length of the content: |
e387ecd7a6ed
inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8386
diff
changeset
|
26 |
e.g. for STAT, receive 8 integers describing the length of the |
e387ecd7a6ed
inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8386
diff
changeset
|
27 |
8 \0-separated string lists ( one list for each lmar!?ic status type ) |
e387ecd7a6ed
inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8386
diff
changeset
|
28 |
|
e387ecd7a6ed
inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8386
diff
changeset
|
29 |
""" |
e387ecd7a6ed
inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8386
diff
changeset
|
30 |
|
e387ecd7a6ed
inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8386
diff
changeset
|
31 |
version = 2 |
6239 | 32 |
|
8386
4aad982111b6
inotify: Abstract the layer format and sizes to a inotify.common dictionary
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8225
diff
changeset
|
33 |
resphdrfmts = { |
4aad982111b6
inotify: Abstract the layer format and sizes to a inotify.common dictionary
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8225
diff
changeset
|
34 |
'STAT': '>llllllll' # status requests |
4aad982111b6
inotify: Abstract the layer format and sizes to a inotify.common dictionary
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8225
diff
changeset
|
35 |
} |
4aad982111b6
inotify: Abstract the layer format and sizes to a inotify.common dictionary
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8225
diff
changeset
|
36 |
resphdrsizes = dict((k, struct.calcsize(v)) |
4aad982111b6
inotify: Abstract the layer format and sizes to a inotify.common dictionary
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8225
diff
changeset
|
37 |
for k, v in resphdrfmts.iteritems()) |
6239 | 38 |
|
39 |
def recvcs(sock): |
|
40 |
cs = cStringIO.StringIO() |
|
41 |
s = True |
|
42 |
try: |
|
43 |
while s: |
|
44 |
s = sock.recv(65536) |
|
45 |
cs.write(s) |
|
46 |
finally: |
|
47 |
sock.shutdown(socket.SHUT_RD) |
|
48 |
cs.seek(0) |
|
49 |
return cs |