~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-01-12 05:35:26 UTC
  • mfrom: (3923.3.4 eintr-safety)
  • Revision ID: pqm@pqm.ubuntu.com-20090112053526-fvc589mub65ppz2m
Add some EINTR-proofing to smart protocol socket code. (Andrew
        Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1549
1549
    """
1550
1550
    b = ''
1551
1551
    while len(b) < bytes:
1552
 
        new = socket.recv(bytes - len(b))
 
1552
        new = until_no_eintr(socket.recv, bytes - len(b))
1553
1553
        if new == '':
1554
1554
            break # eof
1555
1555
        b += new
1564
1564
    """
1565
1565
    chunk_size = 2**16
1566
1566
    for pos in xrange(0, len(bytes), chunk_size):
1567
 
        socket.sendall(bytes[pos:pos+chunk_size])
 
1567
        until_no_eintr(socket.sendall, bytes[pos:pos+chunk_size])
1568
1568
 
1569
1569
 
1570
1570
def dereference_path(path):
1637
1637
            raise errors.NoSuchFile(f)
1638
1638
        raise
1639
1639
 
 
1640
 
 
1641
def until_no_eintr(f, *a, **kw):
 
1642
    """Run f(*a, **kw), retrying if an EINTR error occurs."""
 
1643
    # Borrowed from Twisted's twisted.python.util.untilConcludes function.
 
1644
    while True:
 
1645
        try:
 
1646
            return f(*a, **kw)
 
1647
        except (IOError, OSError), e:
 
1648
            if e.errno == errno.EINTR:
 
1649
                continue
 
1650
            raise
 
1651
 
 
1652
 
1640
1653
if sys.platform == "win32":
1641
1654
    import msvcrt
1642
1655
    def getchar():