XEP-0199: cancel ongoing handlers on session end
and keep track of them but be careful to not store too many fix for #3442
This commit is contained in:
parent
3f10dfe138
commit
c6a0da63ae
@ -66,6 +66,7 @@ class XEP_0199(BasePlugin):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
register_stanza_plugin(Iq, Ping)
|
register_stanza_plugin(Iq, Ping)
|
||||||
|
self.__pending_futures = []
|
||||||
|
|
||||||
self.xmpp.register_handler(
|
self.xmpp.register_handler(
|
||||||
Callback('Ping',
|
Callback('Ping',
|
||||||
@ -90,6 +91,11 @@ class XEP_0199(BasePlugin):
|
|||||||
def session_bind(self, jid):
|
def session_bind(self, jid):
|
||||||
self.xmpp['xep_0030'].add_feature(Ping.namespace)
|
self.xmpp['xep_0030'].add_feature(Ping.namespace)
|
||||||
|
|
||||||
|
def session_end(self, event):
|
||||||
|
for future in self.__pending_futures:
|
||||||
|
future.cancel()
|
||||||
|
self.__pending_futures.clear()
|
||||||
|
|
||||||
def enable_keepalive(self, interval=None, timeout=None):
|
def enable_keepalive(self, interval=None, timeout=None):
|
||||||
if interval:
|
if interval:
|
||||||
self.interval = interval
|
self.interval = interval
|
||||||
@ -97,10 +103,20 @@ class XEP_0199(BasePlugin):
|
|||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
|
|
||||||
self.keepalive = True
|
self.keepalive = True
|
||||||
handler = lambda event=None: asyncio.ensure_future(
|
def handler(event):
|
||||||
self._keepalive(event),
|
# Cleanup futures
|
||||||
loop=self.xmpp.loop,
|
if self.__pending_futures:
|
||||||
)
|
tmp_futures = []
|
||||||
|
for future in self.__pending_futures[:]:
|
||||||
|
if not future.done():
|
||||||
|
tmp_futures.append(future)
|
||||||
|
self.__pending_futures = tmp_futures
|
||||||
|
|
||||||
|
future = asyncio.ensure_future(
|
||||||
|
self._keepalive(event),
|
||||||
|
loop=self.xmpp.loop,
|
||||||
|
)
|
||||||
|
self.__pending_futures.append(future)
|
||||||
self.xmpp.schedule('Ping keepalive',
|
self.xmpp.schedule('Ping keepalive',
|
||||||
self.interval,
|
self.interval,
|
||||||
handler,
|
handler,
|
||||||
|
Loading…
Reference in New Issue
Block a user