~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/medium.py

  • Committer: Ian Clatworthy
  • Date: 2009-09-03 05:09:22 UTC
  • mto: (4634.39.1 pdf-chm-docs)
  • mto: This revision was merged to the branch mainline in revision 4689.
  • Revision ID: ian.clatworthy@canonical.com-20090903050922-ww3c7dk57x8q8dyz
Split Release Notes into topics so easier to navigate and print from chm & html

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006 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
33
33
from bzrlib.lazy_import import lazy_import
34
34
lazy_import(globals(), """
35
35
import atexit
36
 
import thread
37
36
import weakref
38
 
 
39
37
from bzrlib import (
40
38
    debug,
41
39
    errors,
293
291
    def terminate_due_to_error(self):
294
292
        # TODO: This should log to a server log file, but no such thing
295
293
        # exists yet.  Andrew Bennetts 2006-09-29.
296
 
        osutils.until_no_eintr(self.socket.close)
 
294
        self.socket.close()
297
295
        self.finished = True
298
296
 
299
297
    def _write_out(self, bytes):
300
 
        tstart = osutils.timer_func()
301
298
        osutils.send_all(self.socket, bytes, self._report_activity)
302
 
        if 'hpss' in debug.debug_flags:
303
 
            thread_id = thread.get_ident()
304
 
            trace.mutter('%12s: [%s] %d bytes to the socket in %.3fs'
305
 
                         % ('wrote', thread_id, len(bytes),
306
 
                            osutils.timer_func() - tstart))
307
299
 
308
300
 
309
301
class SmartServerPipeStreamMedium(SmartServerStreamMedium):
334
326
            bytes_to_read = protocol.next_read_size()
335
327
            if bytes_to_read == 0:
336
328
                # Finished serving this request.
337
 
                osutils.until_no_eintr(self._out.flush)
 
329
                self._out.flush()
338
330
                return
339
331
            bytes = self.read_bytes(bytes_to_read)
340
332
            if bytes == '':
341
333
                # Connection has been closed.
342
334
                self.finished = True
343
 
                osutils.until_no_eintr(self._out.flush)
 
335
                self._out.flush()
344
336
                return
345
337
            protocol.accept_bytes(bytes)
346
338
 
347
339
    def _read_bytes(self, desired_count):
348
 
        return osutils.until_no_eintr(self._in.read, desired_count)
 
340
        return self._in.read(desired_count)
349
341
 
350
342
    def terminate_due_to_error(self):
351
343
        # TODO: This should log to a server log file, but no such thing
352
344
        # exists yet.  Andrew Bennetts 2006-09-29.
353
 
        osutils.until_no_eintr(self._out.close)
 
345
        self._out.close()
354
346
        self.finished = True
355
347
 
356
348
    def _write_out(self, bytes):
357
 
        osutils.until_no_eintr(self._out.write, bytes)
 
349
        self._out.write(bytes)
358
350
 
359
351
 
360
352
class SmartClientMediumRequest(object):
720
712
 
721
713
    def _accept_bytes(self, bytes):
722
714
        """See SmartClientStreamMedium.accept_bytes."""
723
 
        osutils.until_no_eintr(self._writeable_pipe.write, bytes)
 
715
        self._writeable_pipe.write(bytes)
724
716
        self._report_activity(len(bytes), 'write')
725
717
 
726
718
    def _flush(self):
727
719
        """See SmartClientStreamMedium._flush()."""
728
 
        osutils.until_no_eintr(self._writeable_pipe.flush)
 
720
        self._writeable_pipe.flush()
729
721
 
730
722
    def _read_bytes(self, count):
731
723
        """See SmartClientStreamMedium._read_bytes."""
732
 
        bytes = osutils.until_no_eintr(self._readable_pipe.read, count)
 
724
        bytes = self._readable_pipe.read(count)
733
725
        self._report_activity(len(bytes), 'read')
734
726
        return bytes
735
727
 
749
741
        self._password = password
750
742
        self._port = port
751
743
        self._username = username
752
 
        # for the benefit of progress making a short description of this
753
 
        # transport
754
 
        self._scheme = 'bzr+ssh'
755
744
        # SmartClientStreamMedium stores the repr of this object in its
756
745
        # _DebugCounter so we have to store all the values used in our repr
757
746
        # method before calling the super init.
761
750
        self._vendor = vendor
762
751
        self._write_to = None
763
752
        self._bzr_remote_path = bzr_remote_path
 
753
        # for the benefit of progress making a short description of this
 
754
        # transport
 
755
        self._scheme = 'bzr+ssh'
764
756
 
765
757
    def __repr__(self):
766
 
        if self._port is None:
767
 
            maybe_port = ''
768
 
        else:
769
 
            maybe_port = ':%s' % self._port
770
 
        return "%s(%s://%s@%s%s/)" % (
 
758
        return "%s(connected=%r, username=%r, host=%r, port=%r)" % (
771
759
            self.__class__.__name__,
772
 
            self._scheme,
 
760
            self._connected,
773
761
            self._username,
774
762
            self._host,
775
 
            maybe_port)
 
763
            self._port)
776
764
 
777
765
    def _accept_bytes(self, bytes):
778
766
        """See SmartClientStreamMedium.accept_bytes."""
779
767
        self._ensure_connection()
780
 
        osutils.until_no_eintr(self._write_to.write, bytes)
 
768
        self._write_to.write(bytes)
781
769
        self._report_activity(len(bytes), 'write')
782
770
 
783
771
    def disconnect(self):
784
772
        """See SmartClientMedium.disconnect()."""
785
773
        if not self._connected:
786
774
            return
787
 
        osutils.until_no_eintr(self._read_from.close)
788
 
        osutils.until_no_eintr(self._write_to.close)
 
775
        self._read_from.close()
 
776
        self._write_to.close()
789
777
        self._ssh_connection.close()
790
778
        self._connected = False
791
779
 
814
802
        if not self._connected:
815
803
            raise errors.MediumNotConnected(self)
816
804
        bytes_to_read = min(count, _MAX_READ_SIZE)
817
 
        bytes = osutils.until_no_eintr(self._read_from.read, bytes_to_read)
 
805
        bytes = self._read_from.read(bytes_to_read)
818
806
        self._report_activity(len(bytes), 'read')
819
807
        return bytes
820
808
 
844
832
        """See SmartClientMedium.disconnect()."""
845
833
        if not self._connected:
846
834
            return
847
 
        osutils.until_no_eintr(self._socket.close)
 
835
        self._socket.close()
848
836
        self._socket = None
849
837
        self._connected = False
850
838