/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: Canonical.com Patch Queue Manager
  • Date: 2009-12-21 06:03:07 UTC
  • mfrom: (4665.7.3 serve-init)
  • Revision ID: pqm@pqm.ubuntu.com-20091221060307-uvja3vdy1o6dzzy0
(mbp) example debian init script

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 threading
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
            cur_thread = threading.currentThread()
 
304
            thread_id = getattr(cur_thread, 'ident', None)
 
305
            if thread_id is None:
 
306
                thread_id = cur_thread.getName()
 
307
            trace.mutter('%12s: [%s] %d bytes to the socket in %.3fs'
 
308
                         % ('wrote', thread_id, len(bytes),
 
309
                            osutils.timer_func() - tstart))
299
310
 
300
311
 
301
312
class SmartServerPipeStreamMedium(SmartServerStreamMedium):
326
337
            bytes_to_read = protocol.next_read_size()
327
338
            if bytes_to_read == 0:
328
339
                # Finished serving this request.
329
 
                self._out.flush()
 
340
                osutils.until_no_eintr(self._out.flush)
330
341
                return
331
342
            bytes = self.read_bytes(bytes_to_read)
332
343
            if bytes == '':
333
344
                # Connection has been closed.
334
345
                self.finished = True
335
 
                self._out.flush()
 
346
                osutils.until_no_eintr(self._out.flush)
336
347
                return
337
348
            protocol.accept_bytes(bytes)
338
349
 
339
350
    def _read_bytes(self, desired_count):
340
 
        return self._in.read(desired_count)
 
351
        return osutils.until_no_eintr(self._in.read, desired_count)
341
352
 
342
353
    def terminate_due_to_error(self):
343
354
        # TODO: This should log to a server log file, but no such thing
344
355
        # exists yet.  Andrew Bennetts 2006-09-29.
345
 
        self._out.close()
 
356
        osutils.until_no_eintr(self._out.close)
346
357
        self.finished = True
347
358
 
348
359
    def _write_out(self, bytes):
349
 
        self._out.write(bytes)
 
360
        osutils.until_no_eintr(self._out.write, bytes)
350
361
 
351
362
 
352
363
class SmartClientMediumRequest(object):
712
723
 
713
724
    def _accept_bytes(self, bytes):
714
725
        """See SmartClientStreamMedium.accept_bytes."""
715
 
        self._writeable_pipe.write(bytes)
 
726
        osutils.until_no_eintr(self._writeable_pipe.write, bytes)
716
727
        self._report_activity(len(bytes), 'write')
717
728
 
718
729
    def _flush(self):
719
730
        """See SmartClientStreamMedium._flush()."""
720
 
        self._writeable_pipe.flush()
 
731
        osutils.until_no_eintr(self._writeable_pipe.flush)
721
732
 
722
733
    def _read_bytes(self, count):
723
734
        """See SmartClientStreamMedium._read_bytes."""
724
 
        bytes = self._readable_pipe.read(count)
 
735
        bytes = osutils.until_no_eintr(self._readable_pipe.read, count)
725
736
        self._report_activity(len(bytes), 'read')
726
737
        return bytes
727
738
 
765
776
    def _accept_bytes(self, bytes):
766
777
        """See SmartClientStreamMedium.accept_bytes."""
767
778
        self._ensure_connection()
768
 
        self._write_to.write(bytes)
 
779
        osutils.until_no_eintr(self._write_to.write, bytes)
769
780
        self._report_activity(len(bytes), 'write')
770
781
 
771
782
    def disconnect(self):
772
783
        """See SmartClientMedium.disconnect()."""
773
784
        if not self._connected:
774
785
            return
775
 
        self._read_from.close()
776
 
        self._write_to.close()
 
786
        osutils.until_no_eintr(self._read_from.close)
 
787
        osutils.until_no_eintr(self._write_to.close)
777
788
        self._ssh_connection.close()
778
789
        self._connected = False
779
790
 
802
813
        if not self._connected:
803
814
            raise errors.MediumNotConnected(self)
804
815
        bytes_to_read = min(count, _MAX_READ_SIZE)
805
 
        bytes = self._read_from.read(bytes_to_read)
 
816
        bytes = osutils.until_no_eintr(self._read_from.read, bytes_to_read)
806
817
        self._report_activity(len(bytes), 'read')
807
818
        return bytes
808
819
 
832
843
        """See SmartClientMedium.disconnect()."""
833
844
        if not self._connected:
834
845
            return
835
 
        self._socket.close()
 
846
        osutils.until_no_eintr(self._socket.close)
836
847
        self._socket = None
837
848
        self._connected = False
838
849