def dequeue(self, maxlen):
        self.super = super(DataLinkConnection, self)
        with self.lock:
            if self.state.ESTABLISHED:
                if self.mode.RECV_BUSY_SENT != self.mode.RECV_BUSY:
                    self.mode.RECV_BUSY_SENT = self.mode.RECV_BUSY
                    Ack = (ReceiveReady, ReceiveNotReady)[self.mode.RECV_BUSY]
                    return Ack(self.peer, self.addr, self.recv_ack)

            try: pdu = self.super.dequeue(maxlen, notify=False)
            except IndexError: pdu = None # no pdu available
            if pdu: self.log("dequeue {0} PDU".format(pdu.name))

            if isinstance(pdu, FrameReject):
                self.state.SHUTDOWN = True
                self.close()
            elif isinstance(pdu, Information) and self.state.ESTABLISHED:
                if (self.recv_confs and self.recv_cnt != self.recv_ack):
                    self.log("piggyback ack " + str(self))
                    self.recv_ack = (self.recv_ack + self.recv_confs) % 16
                    self.recv_confs = 0
                pdu.nr = self.recv_ack
                self.send_ready.notify()
            elif isinstance(pdu, DisconnectedMode) and self.state.CLOSE_WAIT:
                dm = Disconnect(dsap=self.peer, ssap=self.addr)
                self.recv_queue.append(dm)
                self.recv_ready.notify()
                self.send_token.notify_all()
            elif pdu is None and self.state.ESTABLISHED:
                if (self.recv_confs and maxlen >= 3 and
                    self.recv_window_slots == 0):
                    self.log("necessary ack " + str(self))
                    self.recv_ack = (self.recv_ack + self.recv_confs) % 16
                    self.recv_confs = 0
                    Ack = (ReceiveReady, ReceiveNotReady)[self.mode.RECV_BUSY]
                    pdu = Ack(self.peer, self.addr, self.recv_ack)
            return pdu
dataset/ETHPy150Open javgh/greenaddress-pos-tools/nfc/llcp/tco.py/DataLinkConnection.dequeue/original