class Sender: def __init__(self, session): self.session = session self.next_id = serial(0) self.commands = [] self._completed = RangedSet() def send(self, cmd): ch = self.session.channel if ch is None: raise SessionDetached() cmd.id = self.next_id self.next_id += 1 if self.session.send_id: self.session.send_id = False ch.session_command_point(cmd.id, 0) self.commands.append(cmd) ch.connection.write_op(cmd) def completed(self, commands): idx = 0 while idx < len(self.commands): cmd = self.commands[idx] if cmd.id in commands: del self.commands[idx] else: idx += 1 for range in commands.ranges: self._completed.add(range.lower, range.upper)
class Receiver: def __init__(self, session): self.session = session self.next_id = None self._completed = RangedSet() def received(self, cmd): if self.next_id == None: raise Exception("todo") cmd.id = self.next_id self.next_id += 1 def completed(self, cmd): if cmd.id == None: raise ValueError("cannot complete unidentified command") self._completed.add(cmd.id) def known_completed(self, commands): completed = RangedSet() for c in self._completed.ranges: for kc in commands.ranges: if c.lower in kc and c.upper in kc: break else: completed.add_range(c) self._completed = completed
def known_completed(self, commands): completed = RangedSet() for c in self._completed.ranges: for kc in commands.ranges: if c.lower in kc and c.upper in kc: break else: completed.add_range(c) self._completed = completed
def read_sequence_set(self): result = RangedSet() size = self.read_uint16() nranges = size / 8 while nranges > 0: lower = self.read_sequence_no() upper = self.read_sequence_no() result.add(lower, upper) nranges -= 1 return result
def read_sequence_set(self): result = RangedSet() size = self.read_uint16() nranges = size/8 while nranges > 0: lower = self.read_sequence_no() upper = self.read_sequence_no() result.add(lower, upper) nranges -= 1 return result
def session_known_completed(self, kcmp): sst = self.get_sst(kcmp) executed = RangedSet() for e in sst.executed.ranges: for ke in kcmp.ranges: if e.lower in ke and e.upper in ke: break else: executed.add_range(e) sst.executed = completed
def session_flush(self, ch, f): rcv = ch.session.receiver if f.expected: if rcv.next_id == None: exp = None else: exp = RangedSet(rcv.next_id) ch.session_expected(exp) if f.confirmed: ch.session_confirmed(rcv._completed) if f.completed: ch.session_completed(rcv._completed)
def __init__(self, session): self.session = session self.next_id = serial(0) self.commands = [] self._completed = RangedSet()
def __init__(self, session): self.session = session self.next_id = None self._completed = RangedSet()