70 self.fout.write("%d\n" % len(v)) |
70 self.fout.write("%d\n" % len(v)) |
71 self.fout.write(v) |
71 self.fout.write(v) |
72 self.fout.flush() |
72 self.fout.flush() |
73 |
73 |
74 def sendstream(self, source): |
74 def sendstream(self, source): |
75 for chunk in source: |
75 for chunk in source.gen: |
76 self.fout.write(chunk) |
76 self.fout.write(chunk) |
77 self.fout.flush() |
77 self.fout.flush() |
78 |
78 |
79 def sendpushresponse(self, ret): |
79 def sendpushresponse(self, rsp): |
80 self.sendresponse('') |
80 self.sendresponse('') |
81 self.sendresponse(str(ret)) |
81 self.sendresponse(str(rsp.res)) |
82 |
82 |
83 def serve_forever(self): |
83 def serve_forever(self): |
84 try: |
84 try: |
85 while self.serve_one(): |
85 while self.serve_one(): |
86 pass |
86 pass |
87 finally: |
87 finally: |
88 if self.lock is not None: |
88 if self.lock is not None: |
89 self.lock.release() |
89 self.lock.release() |
90 sys.exit(0) |
90 sys.exit(0) |
91 |
91 |
|
92 handlers = { |
|
93 str: sendresponse, |
|
94 wireproto.streamres: sendstream, |
|
95 wireproto.pushres: sendpushresponse, |
|
96 } |
|
97 |
92 def serve_one(self): |
98 def serve_one(self): |
93 cmd = self.fin.readline()[:-1] |
99 cmd = self.fin.readline()[:-1] |
94 if cmd and cmd in wireproto.commands: |
100 if cmd and cmd in wireproto.commands: |
95 wireproto.dispatch(self.repo, self, cmd) |
101 rsp = wireproto.dispatch(self.repo, self, cmd) |
|
102 self.handlers[rsp.__class__](self, rsp) |
96 elif cmd: |
103 elif cmd: |
97 impl = getattr(self, 'do_' + cmd, None) |
104 impl = getattr(self, 'do_' + cmd, None) |
98 if impl: |
105 if impl: |
99 r = impl() |
106 r = impl() |
100 if r is not None: |
107 if r is not None: |