/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/smart/protocol.py

  • Committer: Martin Pool
  • Date: 2007-08-20 05:53:39 UTC
  • mfrom: (2727 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2730.
  • Revision ID: mbp@sourcefrog.net-20070820055339-uzei7f7i7jo6tugg
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
client and server.
19
19
"""
20
20
 
21
 
 
22
21
from cStringIO import StringIO
 
22
import time
23
23
 
 
24
from bzrlib import debug
24
25
from bzrlib import errors
25
26
from bzrlib.smart import request
 
27
from bzrlib.trace import log_exception_quietly, mutter
26
28
 
27
29
 
28
30
# Protocol version strings.  These are sent as prefixes of bzr requests and
108
110
                raise
109
111
            except Exception, exception:
110
112
                # everything else: pass to client, flush, and quit
 
113
                log_exception_quietly()
111
114
                self._send_response(request.FailedSmartServerResponse(
112
115
                    ('error', str(exception))))
113
116
                return
297
300
        """
298
301
        self._request = request
299
302
        self._body_buffer = None
 
303
        self._request_start_time = None
300
304
 
301
305
    def call(self, *args):
 
306
        if 'hpss' in debug.debug_flags:
 
307
            mutter('hpss call:   %s', repr(args)[1:-1])
 
308
            self._request_start_time = time.time()
302
309
        self._write_args(args)
303
310
        self._request.finished_writing()
304
311
 
307
314
 
308
315
        After calling this, call read_response_tuple to find the result out.
309
316
        """
 
317
        if 'hpss' in debug.debug_flags:
 
318
            mutter('hpss call w/body: %s (%r...)', repr(args)[1:-1], body[:20])
 
319
            mutter('              %d bytes', len(body))
 
320
            self._request_start_time = time.time()
310
321
        self._write_args(args)
311
322
        bytes = self._encode_bulk_data(body)
312
323
        self._request.accept_bytes(bytes)
318
329
        The body is encoded with one line per readv offset pair. The numbers in
319
330
        each pair are separated by a comma, and no trailing \n is emitted.
320
331
        """
 
332
        if 'hpss' in debug.debug_flags:
 
333
            mutter('hpss call w/readv: %s', repr(args)[1:-1])
 
334
            self._request_start_time = time.time()
321
335
        self._write_args(args)
322
336
        readv_bytes = self._serialise_offsets(body)
323
337
        bytes = self._encode_bulk_data(readv_bytes)
324
338
        self._request.accept_bytes(bytes)
325
339
        self._request.finished_writing()
 
340
        if 'hpss' in debug.debug_flags:
 
341
            mutter('              %d bytes in readv request', len(readv_bytes))
326
342
 
327
343
    def cancel_read_body(self):
328
344
        """After expecting a body, a response code may indicate one otherwise.
339
355
        This should only be called once.
340
356
        """
341
357
        result = self._recv_tuple()
 
358
        if 'hpss' in debug.debug_flags:
 
359
            if self._request_start_time is not None:
 
360
                mutter('   result:   %6.3fs  %s',
 
361
                       time.time() - self._request_start_time,
 
362
                       repr(result)[1:-1])
 
363
                self._request_start_time = None
 
364
            else:
 
365
                mutter('   result:   %s', repr(result)[1:-1])
342
366
        if not expect_body:
343
367
            self._request.finished_reading()
344
368
        return result
360
384
        self._request.finished_reading()
361
385
        self._body_buffer = StringIO(_body_decoder.read_pending_data())
362
386
        # XXX: TODO check the trailer result.
 
387
        if 'hpss' in debug.debug_flags:
 
388
            mutter('              %d body bytes read',
 
389
                   len(self._body_buffer.getvalue()))
363
390
        return self._body_buffer.read(count)
364
391
 
365
392
    def _recv_tuple(self):