~lifeless/ubuntu/lucid/bzr/2.1.2-sru

« back to all changes in this revision

Viewing changes to bzrlib/smart/medium.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2009-03-19 18:16:35 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090319181635-omac7l5epn7x755c
* New upstream release.
* Move to section vcs.
* Bump standards version to 3.8.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
    osutils,
41
41
    symbol_versioning,
42
42
    trace,
 
43
    ui,
43
44
    urlutils,
44
45
    )
45
46
from bzrlib.smart import client, protocol
162
163
        self._push_back(excess)
163
164
        return line
164
165
 
 
166
    def _report_activity(self, bytes, direction):
 
167
        """Notify that this medium has activity.
 
168
 
 
169
        Implementations should call this from all methods that actually do IO.
 
170
        Be careful that it's not called twice, if one method is implemented on
 
171
        top of another.
 
172
 
 
173
        :param bytes: Number of bytes read or written.
 
174
        :param direction: 'read' or 'write' or None.
 
175
        """
 
176
        ui.ui_factory.report_transport_activity(self, bytes, direction)
 
177
 
165
178
 
166
179
class SmartServerStreamMedium(SmartMedium):
167
180
    """Handles smart commands coming over a stream.
274
287
    def _read_bytes(self, desired_count):
275
288
        # We ignore the desired_count because on sockets it's more efficient to
276
289
        # read large chunks (of _MAX_READ_SIZE bytes) at a time.
277
 
        return osutils.until_no_eintr(self.socket.recv, _MAX_READ_SIZE)
 
290
        bytes = osutils.until_no_eintr(self.socket.recv, _MAX_READ_SIZE)
 
291
        self._report_activity(len(bytes), 'read')
 
292
        return bytes
278
293
 
279
294
    def terminate_due_to_error(self):
280
295
        # TODO: This should log to a server log file, but no such thing
283
298
        self.finished = True
284
299
 
285
300
    def _write_out(self, bytes):
286
 
        osutils.send_all(self.socket, bytes)
 
301
        osutils.send_all(self.socket, bytes, self._report_activity)
287
302
 
288
303
 
289
304
class SmartServerPipeStreamMedium(SmartServerStreamMedium):
689
704
    def _accept_bytes(self, bytes):
690
705
        """See SmartClientStreamMedium.accept_bytes."""
691
706
        self._writeable_pipe.write(bytes)
 
707
        self._report_activity(len(bytes), 'write')
692
708
 
693
709
    def _flush(self):
694
710
        """See SmartClientStreamMedium._flush()."""
696
712
 
697
713
    def _read_bytes(self, count):
698
714
        """See SmartClientStreamMedium._read_bytes."""
699
 
        return self._readable_pipe.read(count)
 
715
        bytes = self._readable_pipe.read(count)
 
716
        self._report_activity(len(bytes), 'read')
 
717
        return bytes
700
718
 
701
719
 
702
720
class SmartSSHClientMedium(SmartClientStreamMedium):
730
748
        """See SmartClientStreamMedium.accept_bytes."""
731
749
        self._ensure_connection()
732
750
        self._write_to.write(bytes)
 
751
        self._report_activity(len(bytes), 'write')
733
752
 
734
753
    def disconnect(self):
735
754
        """See SmartClientMedium.disconnect()."""
765
784
        if not self._connected:
766
785
            raise errors.MediumNotConnected(self)
767
786
        bytes_to_read = min(count, _MAX_READ_SIZE)
768
 
        return self._read_from.read(bytes_to_read)
 
787
        bytes = self._read_from.read(bytes_to_read)
 
788
        self._report_activity(len(bytes), 'read')
 
789
        return bytes
769
790
 
770
791
 
771
792
# Port 4155 is the default port for bzr://, registered with IANA.
787
808
    def _accept_bytes(self, bytes):
788
809
        """See SmartClientMedium.accept_bytes."""
789
810
        self._ensure_connection()
790
 
        osutils.send_all(self._socket, bytes)
 
811
        osutils.send_all(self._socket, bytes, self._report_activity)
791
812
 
792
813
    def disconnect(self):
793
814
        """See SmartClientMedium.disconnect()."""
850
871
        # We ignore the desired_count because on sockets it's more efficient to
851
872
        # read large chunks (of _MAX_READ_SIZE bytes) at a time.
852
873
        try:
853
 
            return self._socket.recv(_MAX_READ_SIZE)
 
874
            bytes = osutils.until_no_eintr(self._socket.recv, _MAX_READ_SIZE)
854
875
        except socket.error, e:
855
876
            if len(e.args) and e.args[0] == errno.ECONNRESET:
856
877
                # Callers expect an empty string in that case
857
878
                return ''
858
879
            else:
859
880
                raise
 
881
        else:
 
882
            self._report_activity(len(bytes), 'read')
 
883
            return bytes
860
884
 
861
885
 
862
886
class SmartClientStreamMediumRequest(SmartClientMediumRequest):