~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/medium.py

  • Committer: Robert J. Tanner
  • Date: 2009-06-10 03:56:49 UTC
  • mfrom: (4423 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4425.
  • Revision ID: tanner@real-time.com-20090610035649-7rfx4cls4550zc3c
Merge 1.15.1 back to trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
285
285
        self._push_back(protocol.unused_data)
286
286
 
287
287
    def _read_bytes(self, desired_count):
288
 
        # We ignore the desired_count because on sockets it's more efficient to
289
 
        # read large chunks (of _MAX_READ_SIZE bytes) at a time.
290
 
        bytes = osutils.until_no_eintr(self.socket.recv, _MAX_READ_SIZE)
291
 
        self._report_activity(len(bytes), 'read')
292
 
        return bytes
 
288
        return _read_bytes_from_socket(
 
289
            self.socket.recv, desired_count, self._report_activity)
293
290
 
294
291
    def terminate_due_to_error(self):
295
292
        # TODO: This should log to a server log file, but no such thing
884
881
        """See SmartClientMedium.read_bytes."""
885
882
        if not self._connected:
886
883
            raise errors.MediumNotConnected(self)
887
 
        # We ignore the desired_count because on sockets it's more efficient to
888
 
        # read large chunks (of _MAX_READ_SIZE bytes) at a time.
889
 
        try:
890
 
            bytes = osutils.until_no_eintr(self._socket.recv, _MAX_READ_SIZE)
891
 
        except socket.error, e:
892
 
            if len(e.args) and e.args[0] == errno.ECONNRESET:
893
 
                # Callers expect an empty string in that case
894
 
                return ''
895
 
            else:
896
 
                raise
897
 
        else:
898
 
            self._report_activity(len(bytes), 'read')
899
 
            return bytes
 
884
        return _read_bytes_from_socket(
 
885
            self._socket.recv, count, self._report_activity)
900
886
 
901
887
 
902
888
class SmartClientStreamMediumRequest(SmartClientMediumRequest):
938
924
        """
939
925
        self._medium._flush()
940
926
 
 
927
 
 
928
def _read_bytes_from_socket(sock, desired_count, report_activity):
 
929
    # We ignore the desired_count because on sockets it's more efficient to
 
930
    # read large chunks (of _MAX_READ_SIZE bytes) at a time.
 
931
    try:
 
932
        bytes = osutils.until_no_eintr(sock, _MAX_READ_SIZE)
 
933
    except socket.error, e:
 
934
        if len(e.args) and e.args[0] in (errno.ECONNRESET, 10054):
 
935
            # The connection was closed by the other side.  Callers expect an
 
936
            # empty string to signal end-of-stream.
 
937
            bytes = ''
 
938
        else:
 
939
            raise
 
940
    else:
 
941
        report_activity(len(bytes), 'read')
 
942
    return bytes
 
943