/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/smart/medium.py

  • Committer: Jonathan Lange
  • Date: 2009-12-09 09:20:42 UTC
  • mfrom: (4881 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4907.
  • Revision ID: jml@canonical.com-20091209092042-s2zgqcf8f39yzxpj
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
from bzrlib import (
38
38
    debug,
39
39
    errors,
40
 
    osutils,
41
40
    symbol_versioning,
42
41
    trace,
43
42
    ui,
46
45
from bzrlib.smart import client, protocol, request, vfs
47
46
from bzrlib.transport import ssh
48
47
""")
49
 
 
 
48
#usually already imported, and getting IllegalScoperReplacer on it here.
 
49
from bzrlib import osutils
50
50
 
51
51
# We must not read any more than 64k at a time so we don't risk "no buffer
52
52
# space available" errors on some platforms.  Windows in particular is likely
291
291
    def terminate_due_to_error(self):
292
292
        # TODO: This should log to a server log file, but no such thing
293
293
        # exists yet.  Andrew Bennetts 2006-09-29.
294
 
        self.socket.close()
 
294
        osutils.until_no_eintr(self.socket.close)
295
295
        self.finished = True
296
296
 
297
297
    def _write_out(self, bytes):
326
326
            bytes_to_read = protocol.next_read_size()
327
327
            if bytes_to_read == 0:
328
328
                # Finished serving this request.
329
 
                self._out.flush()
 
329
                osutils.until_no_eintr(self._out.flush)
330
330
                return
331
331
            bytes = self.read_bytes(bytes_to_read)
332
332
            if bytes == '':
333
333
                # Connection has been closed.
334
334
                self.finished = True
335
 
                self._out.flush()
 
335
                osutils.until_no_eintr(self._out.flush)
336
336
                return
337
337
            protocol.accept_bytes(bytes)
338
338
 
339
339
    def _read_bytes(self, desired_count):
340
 
        return self._in.read(desired_count)
 
340
        return osutils.until_no_eintr(self._in.read, desired_count)
341
341
 
342
342
    def terminate_due_to_error(self):
343
343
        # TODO: This should log to a server log file, but no such thing
344
344
        # exists yet.  Andrew Bennetts 2006-09-29.
345
 
        self._out.close()
 
345
        osutils.until_no_eintr(self._out.close)
346
346
        self.finished = True
347
347
 
348
348
    def _write_out(self, bytes):
349
 
        self._out.write(bytes)
 
349
        osutils.until_no_eintr(self._out.write, bytes)
350
350
 
351
351
 
352
352
class SmartClientMediumRequest(object):
472
472
        if not line.endswith('\n'):
473
473
            # end of file encountered reading from server
474
474
            raise errors.ConnectionReset(
475
 
                "please check connectivity and permissions")
 
475
                "Unexpected end of message. Please check connectivity "
 
476
                "and permissions, and report a bug if problems persist.")
476
477
        return line
477
478
 
478
479
    def _read_line(self):
518
519
        # Increment the count in the WeakKeyDictionary
519
520
        value = self.counts[params.medium]
520
521
        value['count'] += 1
521
 
        request_method = request.request_handlers.get(params.method)
 
522
        try:
 
523
            request_method = request.request_handlers.get(params.method)
 
524
        except KeyError:
 
525
            # A method we don't know about doesn't count as a VFS method.
 
526
            return
522
527
        if issubclass(request_method, vfs.VfsRequest):
523
528
            value['vfs_count'] += 1
524
529
 
707
712
 
708
713
    def _accept_bytes(self, bytes):
709
714
        """See SmartClientStreamMedium.accept_bytes."""
710
 
        self._writeable_pipe.write(bytes)
 
715
        osutils.until_no_eintr(self._writeable_pipe.write, bytes)
711
716
        self._report_activity(len(bytes), 'write')
712
717
 
713
718
    def _flush(self):
714
719
        """See SmartClientStreamMedium._flush()."""
715
 
        self._writeable_pipe.flush()
 
720
        osutils.until_no_eintr(self._writeable_pipe.flush)
716
721
 
717
722
    def _read_bytes(self, count):
718
723
        """See SmartClientStreamMedium._read_bytes."""
719
 
        bytes = self._readable_pipe.read(count)
 
724
        bytes = osutils.until_no_eintr(self._readable_pipe.read, count)
720
725
        self._report_activity(len(bytes), 'read')
721
726
        return bytes
722
727
 
760
765
    def _accept_bytes(self, bytes):
761
766
        """See SmartClientStreamMedium.accept_bytes."""
762
767
        self._ensure_connection()
763
 
        self._write_to.write(bytes)
 
768
        osutils.until_no_eintr(self._write_to.write, bytes)
764
769
        self._report_activity(len(bytes), 'write')
765
770
 
766
771
    def disconnect(self):
767
772
        """See SmartClientMedium.disconnect()."""
768
773
        if not self._connected:
769
774
            return
770
 
        self._read_from.close()
771
 
        self._write_to.close()
 
775
        osutils.until_no_eintr(self._read_from.close)
 
776
        osutils.until_no_eintr(self._write_to.close)
772
777
        self._ssh_connection.close()
773
778
        self._connected = False
774
779
 
797
802
        if not self._connected:
798
803
            raise errors.MediumNotConnected(self)
799
804
        bytes_to_read = min(count, _MAX_READ_SIZE)
800
 
        bytes = self._read_from.read(bytes_to_read)
 
805
        bytes = osutils.until_no_eintr(self._read_from.read, bytes_to_read)
801
806
        self._report_activity(len(bytes), 'read')
802
807
        return bytes
803
808
 
827
832
        """See SmartClientMedium.disconnect()."""
828
833
        if not self._connected:
829
834
            return
830
 
        self._socket.close()
 
835
        osutils.until_no_eintr(self._socket.close)
831
836
        self._socket = None
832
837
        self._connected = False
833
838