def run_as_initiator(self, terminate=(lambda : False)):
    recv_timeout = (0.001 * (self.cfg['recv-lto'] + 10))
    symm = 0
    try:
        pdu = self.collect(delay=0.01)
        while (not terminate()):
            if (pdu is None):
                pdu = Symmetry()
            pdu = self.exchange(pdu, recv_timeout)
            if (pdu is None):
                return self.terminate(reason='link disruption')
            if (pdu == Disconnect(0, 0)):
                return self.terminate(reason='remote choice')
            symm = ((symm + 1) if (type(pdu) == Symmetry) else 0)
            self.dispatch(pdu)
            pdu = self.collect(delay=0.001)
            if ((pdu is None) and (symm >= 10)):
                pdu = self.collect(delay=0.05)
        else:
            self.terminate(reason='local choice')
    except KeyboardInterrupt:
        print
        self.terminate(reason='local choice')
        raise KeyboardInterrupt
    except IOError:
        self.terminate(reason='input/output error')
        raise SystemExit
    finally:
        log.debug('llc run loop terminated on initiator')
def run_as_initiator(self, terminate=(lambda : False)):
    recv_timeout = (0.001 * (self.cfg['recv-lto'] + 10))
    symm = 0
    try:
        pdu = self.collect(delay=0.01)
        while (not terminate()):
            if (pdu is None):
                pdu = Symmetry()
            pdu = self.exchange(pdu, recv_timeout)
            if (pdu is None):
                return self.terminate(reason='link disruption')
            if (pdu == Disconnect(0, 0)):
                return self.terminate(reason='remote choice')
            symm = ((symm + 1) if (type(pdu) == Symmetry) else 0)
            self.dispatch(pdu)
            pdu = self.collect(delay=0.001)
            if ((pdu is None) and (symm >= 10)):
                pdu = self.collect(delay=0.05)
        else:
            self.terminate(reason='local choice')
    except KeyboardInterrupt:
        print
        self.terminate(reason='local choice')
        raise KeyboardInterrupt
    except IOError:
        self.terminate(reason='input/output error')
        raise SystemExit
    finally:
        log.debug('llc run loop terminated on initiator')