~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/medium.py

  • Committer: Vincent Ladeuil
  • Date: 2010-02-09 20:33:43 UTC
  • mto: (5029.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5030.
  • Revision ID: v.ladeuil+lp@free.fr-20100209203343-ktxx7t0xvptvjnt1
Move TestingPathFilteringServer to bzrlib.tests.test_server

Show diffs side-by-side

added added

removed removed

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