~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Martin Pool
  • Date: 2006-10-21 02:33:37 UTC
  • mto: (2091.2.1 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 2092.
  • Revision ID: mbp@sourcefrog.net-20061021023337-e517eaadd87fc778
Avoid MSG_WAITALL as it doesn't work on Windows

Show diffs side-by-side

added added

removed removed

Lines of Context:
1090
1090
    if _cached_user_encoding is None:
1091
1091
        _cached_user_encoding = 'ascii'
1092
1092
    return _cached_user_encoding
 
1093
 
 
1094
 
 
1095
def recv_all(socket, bytes):
 
1096
    """Receive an exact number of bytes.
 
1097
 
 
1098
    Regular Socket.recv() may return less than the requested number of bytes,
 
1099
    dependning on what's in the OS buffer.  MSG_WAITALL is not available
 
1100
    on all platforms, but this should work everywhere.  This will return
 
1101
    less than the requested amount if the remote end closes.
 
1102
 
 
1103
    This isn't optimized and is intended mostly for use in testing.
 
1104
    """
 
1105
    b = ''
 
1106
    while len(b) < bytes:
 
1107
        new = socket.recv(bytes - len(b))
 
1108
        if new == '':
 
1109
            break # eof
 
1110
        b += new
 
1111
    return b
 
1112