~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/smart.py

  • Committer: Andrew Bennetts
  • Date: 2006-10-13 06:07:17 UTC
  • mto: (2018.2.34 smart server unicode)
  • mto: This revision was merged to the branch mainline in revision 2144.
  • Revision ID: andrew.bennetts@canonical.com-20061013060717-ccf711d3149c0a17
Ensure that a request's next_read_size() is 0 once an error response is sent.

This is done by setting the finished flag in _send_response, and removing
sync_with_request entirely.

Also s/_finished_reading/_finished/ in SmartServerRequestProtocolOne.

Show diffs side-by-side

added added

removed removed

Lines of Context:
269
269
    def __init__(self, backing_transport, write_func):
270
270
        self._backing_transport = backing_transport
271
271
        self.excess_buffer = ''
272
 
        self._finished_reading = False
 
272
        self._finished = False
273
273
        self.in_buffer = ''
274
274
        self.has_dispatched = False
275
275
        self.request = None
301
301
                    self.in_buffer = ''
302
302
                    self._send_response(self.request.response.args,
303
303
                        self.request.response.body)
304
 
                self.sync_with_request(self.request)
305
304
            except KeyboardInterrupt:
306
305
                raise
307
306
            except Exception, exception:
308
307
                # everything else: pass to client, flush, and quit
309
308
                self._send_response(('error', str(exception)))
310
 
                return None
 
309
                return
311
310
 
312
311
        if self.has_dispatched:
313
 
            if self._finished_reading:
 
312
            if self._finished:
314
313
                # nothing to do.XXX: this routine should be a single state 
315
314
                # machine too.
316
315
                self.excess_buffer += self.in_buffer
326
325
                self.request.end_of_body()
327
326
                assert self.request.finished_reading, \
328
327
                    "no more body, request not finished"
329
 
            self.sync_with_request(self.request)
330
328
            if self.request.response is not None:
331
329
                self._send_response(self.request.response.args,
332
330
                    self.request.response.body)
338
336
 
339
337
    def _send_response(self, args, body=None):
340
338
        """Send a smart server response down the output stream."""
 
339
        assert not self._finished, 'response already sent'
 
340
        self._finished = True
341
341
        self._write_func(_encode_tuple(args))
342
342
        if body is not None:
343
343
            assert isinstance(body, str), 'body must be a str'
344
344
            bytes = self._encode_bulk_data(body)
345
345
            self._write_func(bytes)
346
346
 
347
 
    def sync_with_request(self, request):
348
 
        self._finished_reading = request.finished_reading
349
 
        
350
347
    def next_read_size(self):
351
 
        if self._finished_reading:
 
348
        if self._finished:
352
349
            return 0
353
350
        if self._body_decoder is None:
354
351
            return 1