Exemplo n.º 1
0
class KA(object):
    def __init__(self, log, proto):
        self._generator = self._keepalive(proto)
        self.send_timer = SendTimer(log, proto.negotiated.holdtime)

    def _keepalive(self, proto):
        need_ka = False
        generator = None

        while True:
            # SEND KEEPALIVES
            need_ka |= self.send_timer.need_ka()

            if need_ka:
                if not generator:
                    generator = proto.new_keepalive()
                    need_ka = False

            if not generator:
                yield False
                continue

            try:
                # try to close the generator and raise a StopIteration in one call
                generator.next()
                generator.next()
                # still running
                yield True
            except NetworkError:
                raise Notify(
                    4, 0,
                    'problem with network while trying to send keepalive')
            except StopIteration:
                generator = None
                yield False

    def __call__(self):
        #  True  if we need or are trying
        #  False if we do not need to send one
        try:
            return self._generator.next()
        except StopIteration:
            raise Notify(4, 0, 'could not send keepalive')
Exemplo n.º 2
0
class KA (object):
	def __init__ (self,log,proto):
		self._generator = self._keepalive(proto)
		self.send_timer = SendTimer(log,proto.negotiated.holdtime)

	def _keepalive (self,proto):
		need_ka   = False
		generator = None

		while True:
			# SEND KEEPALIVES
			need_ka |= self.send_timer.need_ka()

			if need_ka:
				if not generator:
					generator = proto.new_keepalive()
					need_ka = False

			if not generator:
				yield False
				continue

			try:
				# try to close the generator and raise a StopIteration in one call
				generator.next()
				generator.next()
				# still running
				yield True
			except NetworkError:
				raise Notify(4,0,'problem with network while trying to send keepalive')
			except StopIteration:
				generator = None
				yield False

	def __call__ (self):
		#  True  if we need or are trying
		#  False if we do not need to send one
		try:
			return self._generator.next()
		except StopIteration:
			raise Notify(4,0,'could not send keepalive')
Exemplo n.º 3
0
	def __init__ (self, log, proto):
		self._generator = self._keepalive(proto)
		self.send_timer = SendTimer(log,proto.negotiated.holdtime)
Exemplo n.º 4
0
	def __init__ (self,log,proto):
		self._generator = self._keepalive(proto)
		self.send_timer = SendTimer(log,proto.negotiated.holdtime)