~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/protocol.py

  • Committer: John Arbash Meinel
  • Date: 2009-12-16 20:01:49 UTC
  • mfrom: (4903 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4904.
  • Revision ID: john@arbash-meinel.com-20091216200149-jg71giy0qp27bfv0
Merge bzr.dev 4903, resolve NEWS

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."""