comparison mercurial/wireprotov2peer.py @ 40019:f5a05bb48116

wireprotov2: change name and behavior of readframe() In the near future, we will want to support performing I/O from other sources. Let's rename readframe() to readdata() and tweak its logic to support future growth. Differential Revision: https://phab.mercurial-scm.org/D4771
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 26 Sep 2018 15:53:49 -0700
parents d06834e0f48e
children 86b22a4cfab1
comparison
equal deleted inserted replaced
40018:f80db6adabbe 40019:f5a05bb48116
146 self._ui = ui 146 self._ui = ui
147 self._reactor = clientreactor 147 self._reactor = clientreactor
148 self._requests = {} 148 self._requests = {}
149 self._futures = {} 149 self._futures = {}
150 self._responses = {} 150 self._responses = {}
151 self._frameseof = False
151 152
152 def callcommand(self, command, args, f): 153 def callcommand(self, command, args, f):
153 """Register a request to call a command. 154 """Register a request to call a command.
154 155
155 Returns an iterable of frames that should be sent over the wire. 156 Returns an iterable of frames that should be sent over the wire.
178 if action != 'sendframes': 179 if action != 'sendframes':
179 raise error.ProgrammingError('%s not yet supported' % action) 180 raise error.ProgrammingError('%s not yet supported' % action)
180 181
181 return meta['framegen'] 182 return meta['framegen']
182 183
183 def readframe(self, fh): 184 def readdata(self, framefh):
184 """Attempt to read and process a frame. 185 """Attempt to read data and do work.
185 186
186 Returns None if no frame was read. Presumably this means EOF. 187 Returns None if no data was read. Presumably this means we're
187 """ 188 done with all read I/O.
188 frame = wireprotoframing.readframe(fh) 189 """
189 if frame is None: 190 if not self._frameseof:
190 # TODO tell reactor? 191 frame = wireprotoframing.readframe(framefh)
191 return 192 if frame is None:
192 193 # TODO tell reactor?
193 self._ui.note(_('received %r\n') % frame) 194 self._frameseof = True
194 self._processframe(frame) 195 else:
196 self._ui.note(_('received %r\n') % frame)
197 self._processframe(frame)
198
199 if self._frameseof:
200 return None
195 201
196 return True 202 return True
197 203
198 def _processframe(self, frame): 204 def _processframe(self, frame):
199 """Process a single read frame.""" 205 """Process a single read frame."""