def recvall(stream):
    """
    receive all the data in the cudam_socket
    :param stream: cudam_socket or request, both of which have recv method
    :return: the whole string received by the cudam_socket
    :rtype: bytearray
    """
    BUFF_SIZE = 4096
    data = b''
    while True:
        part = stream.recv(BUFF_SIZE)
        data += part
        if len(part) < BUFF_SIZE:
            break
    return data
