def dequeue(self, max_size):
        if max_size < 2:
            return None
        with self.llc.lock:
            if len(self.sdres) > 0 or len(self.sdreq) > 0:
                pdu = ServiceNameLookup(dsap=1, ssap=1)
                max_size -= len(pdu)
                while max_size > 0:
                    try: pdu.sdres.append(self.sdres.popleft())
                    except IndexError: break
                for i in range(len(self.sdreq)):
                    tid, name = self.sdreq[0]
                    if 1 + len(name) > max_size:
                        self.sdreq.rotate(-1)
                    else:
                        pdu.sdreq.append(self.sdreq.popleft())
                        self.sent[tid] = name
                return pdu
            if len(self.dmpdu) > 0 and max_size >= 2:
                return self.dmpdu.popleft()
dataset/ETHPy150Open javgh/greenaddress-pos-tools/nfc/llcp/llc.py/ServiceDiscovery.dequeue/original