Mercurial > hg
comparison mercurial/sshserver.py @ 30466:2add671bf55b
wireproto: perform chunking and compression at protocol layer (API)
Currently, the "streamres" response type is populated with a generator
of chunks with compression possibly already applied. This puts the onus
on commands to perform chunking and compression. Architecturally, I
think this is the wrong place to perform this work. I think commands
should say "here is the data" and the protocol layer should take care
of encoding the final bytes to put on the wire.
Additionally, upcoming commits will improve wire protocol support for
compression. Having a central place for performing compression in the
protocol transport layer will be easier than having to deal with
compression at the commands layer.
This commit refactors the "streamres" response type to accept either
a generator or an object with "read." Additionally, the type now
accepts a flag indicating whether the response is a "version 1
compressible" response. This basically identifies all commands
currently performing compression. I could have used a special type
for this, but a flag works just as well. The argument name
foreshadows the introduction of wire protocol changes, hence the "v1."
The code for chunking and compressing has been moved to the output
generation function for each protocol transport. Some code has been
inlined, resulting in the deletion of now unused methods.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sun, 20 Nov 2016 13:50:45 -0800 |
parents | d105195436c0 |
children | b3a9ef3d30e8 |
comparison
equal
deleted
inserted
replaced
30465:40a1871eea5e | 30466:2add671bf55b |
---|---|
66 count = int(self.fin.readline()) | 66 count = int(self.fin.readline()) |
67 | 67 |
68 def redirect(self): | 68 def redirect(self): |
69 pass | 69 pass |
70 | 70 |
71 def groupchunks(self, fh): | |
72 return iter(lambda: fh.read(4096), '') | |
73 | |
74 def compresschunks(self, chunks): | |
75 for chunk in chunks: | |
76 yield chunk | |
77 | |
78 def sendresponse(self, v): | 71 def sendresponse(self, v): |
79 self.fout.write("%d\n" % len(v)) | 72 self.fout.write("%d\n" % len(v)) |
80 self.fout.write(v) | 73 self.fout.write(v) |
81 self.fout.flush() | 74 self.fout.flush() |
82 | 75 |
83 def sendstream(self, source): | 76 def sendstream(self, source): |
84 write = self.fout.write | 77 write = self.fout.write |
85 for chunk in source.gen: | 78 |
79 if source.reader: | |
80 gen = iter(lambda: source.reader.read(4096), '') | |
81 else: | |
82 gen = source.gen | |
83 | |
84 for chunk in gen: | |
86 write(chunk) | 85 write(chunk) |
87 self.fout.flush() | 86 self.fout.flush() |
88 | 87 |
89 def sendpushresponse(self, rsp): | 88 def sendpushresponse(self, rsp): |
90 self.sendresponse('') | 89 self.sendresponse('') |