allow to wait for more than one answer at the same time with SendAndCallForResponse. Fixes #4299

This commit is contained in:
Yann Leboulanger 2009-02-15 13:17:33 +00:00
parent 06d4188411
commit f443673bfd
1 changed files with 18 additions and 18 deletions

View File

@ -463,20 +463,20 @@ class XMPPDispatcher(PlugIn):
if not res: if not res:
return return
self._owner.remove_timeout() self._owner.remove_timeout()
if self._expected[self._witid] is None: for (_id, _iq) in self._expected.items():
# If the expected Stanza would have arrived, ProcessNonBlocking would if _iq is None:
# have placed the reply stanza in there # If the expected Stanza would have arrived, ProcessNonBlocking
return # would have placed the reply stanza in there
if self._witid in self.on_responses: continue
i = self._witid # copy id cause it can change in resp() call if _id in self.on_responses:
self._owner.onreceive(None) self._owner.onreceive(None)
resp, args = self.on_responses[self._witid] resp, args = self.on_responses[_id]
del(self.on_responses[self._witid]) del(self.on_responses[_id])
if args is None: if args is None:
resp(self._expected[self._witid]) resp(_iq)
else: else:
resp(self._owner, self._expected[self._witid], **args) resp(self._owner, _iq, **args)
del self._expected[i] del self._expected[_id]
def SendAndWaitForResponse(self, stanza, timeout=None, func=None, args=None): def SendAndWaitForResponse(self, stanza, timeout=None, func=None, args=None):
''' '''
@ -487,14 +487,14 @@ class XMPPDispatcher(PlugIn):
''' '''
if timeout is None: if timeout is None:
timeout = DEFAULT_TIMEOUT_SECONDS timeout = DEFAULT_TIMEOUT_SECONDS
self._witid = self.send(stanza) _waitid = self.send(stanza)
if func: if func:
self.on_responses[self._witid] = (func, args) self.on_responses[_waitid] = (func, args)
if timeout: if timeout:
self._owner.set_timeout(timeout) self._owner.set_timeout(timeout)
self._owner.onreceive(self._WaitForData) self._owner.onreceive(self._WaitForData)
self._expected[self._witid] = None self._expected[_waitid] = None
return self._witid return _waitid
def SendAndCallForResponse(self, stanza, func=None, args=None): def SendAndCallForResponse(self, stanza, func=None, args=None):
''' Put stanza on the wire and call back when recipient replies. ''' Put stanza on the wire and call back when recipient replies.