Function used to receive packets and check their hashret

def _sndrcv_rcv(pks, hsent, stopevent, nbrecv, notans, verbose, chainCC,
                multi, _storage_policy=None):
    """Function used to receive packets and check their hashret"""
    if not _storage_policy:
        _storage_policy = lambda x, y: (x, y)
    ans = []

    def _get_pkt():
        # SuperSocket.select() returns, according to each socket type,
        # the selected sockets + the function to recv() the packets (or None)
        # (when sockets aren't selectable, should be nonblock_recv)
        selected, read_func = pks.select([pks])
        read_func = read_func or pks.__class__.recv
        if selected:
            return read_func(selected[0])

    try:
        while True:
            r = _get_pkt()
            if stopevent.is_set():
                break
            if r is None:
                continue
            ok = False
            h = r.hashret()
            if h in hsent:
                hlst = hsent[h]
                for i, sentpkt in enumerate(hlst):
                    if r.answers(sentpkt):
                        ans.append(_storage_policy(sentpkt, r))
                        if verbose > 1:
                            os.write(1, b"*")
                        ok = True
                        if not multi:
                            del hlst[i]
                            notans -= 1
                        else:
                            if not hasattr(sentpkt, '_answered'):
                                notans -= 1
                            sentpkt._answered = 1
                        break
            if notans == 0 and not multi:
                del r
                break
            if not ok:
                if verbose > 1:
                    os.write(1, b".")
                nbrecv += 1
                if conf.debug_match:
                    debug.recv.append(r)
            del r
    except KeyboardInterrupt:
        if chainCC:
            raise
    finally:
        stopevent.set()
    return (hsent, ans, nbrecv, notans)