import socket
import searchengine.debugtools

def hex2bin(arr):
    return bytearray.fromhex("".join("{:02x}".format(hex_num) for hex_num in arr))

def recvall(s, ln):
    remaining = ln
    recvd_data = b''
    while remaining > 0:
        r = b''
        try:
            r = s.recv(remaining)
            if not r:
                return r
            remaining -= len(r)
            recvd_data += r
        except Exception as e:
            searchengine.debugtools.log_exception(e)
            return r
    return recvd_data
        