def on_tick(self, conn_id, now): with self._lock: if self._status != ContextStatus.READY: return time_elapsed = now - self._last_keep_alive_time if time_elapsed.total_seconds() < self._keep_alive_interval: return ret, msg, req = KeepAlive.pack_req(self.get_sync_conn_id()) if ret != RET_OK: logger.warning("KeepAlive.pack_req fail: {0}".format(msg)) return ret, result = self._net_mgr.send(conn_id, req, is_sync=False) if ret != RET_OK: return self._last_keep_alive_time = now
def on_activate(self, conn_id, now): with self._lock: if self._status != ContextStatus.Ready: return time_elapsed = now - self._last_keep_alive_time if time_elapsed.total_seconds() < self._keep_alive_interval: return logger.debug("Keepalive: conn_id={};".format(conn_id)) ret, msg, req = KeepAlive.pack_req(self.get_sync_conn_id()) if ret != RET_OK: logger.warning("KeepAlive.pack_req fail: {0}".format(msg)) return ret, msg = self._net_mgr.send(conn_id, req) if ret != RET_OK: return self._last_keep_alive_time = now