/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: Canonical.com Patch Queue Manager
  • Date: 2009-12-16 18:11:26 UTC
  • mfrom: (4889.4.3 2.1.0b4-proto3-buffering)
  • Revision ID: pqm@pqm.ubuntu.com-20091216181126-rzour6b702sb9sev
(jam) Change the protocol3 buffering code to use a size buffer rather
        than a call count buffer

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2008, 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
1066
1066
class _ProtocolThreeEncoder(object):
1067
1067
 
1068
1068
    response_marker = request_marker = MESSAGE_VERSION_THREE
 
1069
    BUFFER_SIZE = 1024*1024 # 1 MiB buffer before flushing
1069
1070
 
1070
1071
    def __init__(self, write_func):
1071
1072
        self._buf = []
 
1073
        self._buf_len = 0
1072
1074
        self._real_write_func = write_func
1073
1075
 
1074
1076
    def _write_func(self, bytes):
1081
1083
        #       Note that osutils.send_all always sends 64kB chunks anyway, so
1082
1084
        #       we might just push out smaller bits at a time?
1083
1085
        self._buf.append(bytes)
1084
 
        if len(self._buf) > 100:
 
1086
        self._buf_len += len(bytes)
 
1087
        if self._buf_len > self.BUFFER_SIZE:
1085
1088
            self.flush()
1086
1089
 
1087
1090
    def flush(self):
1088
1091
        if self._buf:
1089
1092
            self._real_write_func(''.join(self._buf))
1090
1093
            del self._buf[:]
 
1094
            self._buf_len = 0
1091
1095
 
1092
1096
    def _serialise_offsets(self, offsets):
1093
1097
        """Serialise a readv offset list."""