def METHOD_NAME(s, n):
    '''Receive n bytes from a socket, or fail'''
    rv = bytearray()
    while n > 0:
        d = s.recv(n)
        if not d:
            raise IOError('Unexpected end of stream')
        rv.extend(d)
        n -= len(d)
    return rv