add a now argument to the send function, so that stanza is sent instantly instead of added to queue. Use it to send answer to adhoc command when we disconnect. fixes #3008 and #2808

This commit is contained in:
Yann Leboulanger 2007-03-15 12:53:29 +00:00
parent f09799f9d9
commit efaa1a18e7
3 changed files with 14 additions and 10 deletions

View File

@ -135,7 +135,7 @@ class ChangeStatusCommand(AdHocCommand):
# if going offline, we need to push response so it won't go into # if going offline, we need to push response so it won't go into
# queue and disappear # queue and disappear
self.connection.connection.send(response, presencetype == 'offline') self.connection.connection.send(response, now = presencetype == 'offline')
# send new status # send new status
gajim.interface.roster.send_status(self.connection.name, presencetype, gajim.interface.roster.send_status(self.connection.name, presencetype,

View File

@ -398,11 +398,11 @@ class Dispatcher(PlugIn):
Additional callback arguments can be specified in args. ''' Additional callback arguments can be specified in args. '''
self.SendAndWaitForResponse(stanza, 0, func, args) self.SendAndWaitForResponse(stanza, 0, func, args)
def send(self, stanza, is_message = False): def send(self, stanza, is_message = False, now = False):
''' Serialise stanza and put it on the wire. Assign an unique ID to it before send. ''' Serialise stanza and put it on the wire. Assign an unique ID to it before send.
Returns assigned ID.''' Returns assigned ID.'''
if type(stanza) in [type(''), type(u'')]: if type(stanza) in [type(''), type(u'')]:
return self._owner.Connection.send(stanza) return self._owner.Connection.send(stanza, now = now)
if not isinstance(stanza, Protocol): if not isinstance(stanza, Protocol):
_ID=None _ID=None
elif not stanza.getID(): elif not stanza.getID():
@ -426,9 +426,9 @@ class Dispatcher(PlugIn):
stanza.setNamespace(self._owner.Namespace) stanza.setNamespace(self._owner.Namespace)
stanza.setParent(self._metastream) stanza.setParent(self._metastream)
if is_message: if is_message:
self._owner.Connection.send(stanza, True) self._owner.Connection.send(stanza, True, now = now)
else: else:
self._owner.Connection.send(stanza) self._owner.Connection.send(stanza, now = now)
return _ID return _ID
def disconnect(self): def disconnect(self):

View File

@ -138,7 +138,7 @@ class SSLWrapper:
raise NotImplementedException() raise NotImplementedException()
def send(self, data, flags=None): def send(self, data, flags=None, now = False):
raise NotImplementedException() raise NotImplementedException()
class PyOpenSSLWrapper(SSLWrapper): class PyOpenSSLWrapper(SSLWrapper):
@ -178,7 +178,7 @@ class PyOpenSSLWrapper(SSLWrapper):
raise SSLWrapper.Error(self.sock or self.sslobj, e) raise SSLWrapper.Error(self.sock or self.sslobj, e)
return retval return retval
def send(self, data, flags=None): def send(self, data, flags=None, now = False):
try: try:
if flags is None: return self.sslobj.send(data) if flags is None: return self.sslobj.send(data)
else: return self.sslobj.send(data, flags) else: return self.sslobj.send(data, flags)
@ -219,7 +219,7 @@ class StdlibSSLWrapper(SSLWrapper):
raise SSLWrapper.Error(self.sock or self.sslobj, e) raise SSLWrapper.Error(self.sock or self.sslobj, e)
return None return None
def send(self, data, flags=None): def send(self, data, flags=None, now = False):
# we simply ignore flags since ssl object doesn't support it # we simply ignore flags since ssl object doesn't support it
try: try:
return self.sslobj.write(data) return self.sslobj.write(data)
@ -574,7 +574,7 @@ class NonBlockingTcp(PlugIn, IdleObject):
self.on_connect = None self.on_connect = None
return True return True
def send(self, raw_data): def send(self, raw_data, now = False):
'''Append raw_data to the queue of messages to be send. '''Append raw_data to the queue of messages to be send.
If supplied data is unicode string, encode it to utf-8. If supplied data is unicode string, encode it to utf-8.
''' '''
@ -585,7 +585,11 @@ class NonBlockingTcp(PlugIn, IdleObject):
r = r.encode('utf-8') r = r.encode('utf-8')
elif not isinstance(r, str): elif not isinstance(r, str):
r = ustr(r).encode('utf-8') r = ustr(r).encode('utf-8')
self.sendqueue.append(r) if now:
self.sendqueue.insert(0, r)
self._do_send()
else:
self.sendqueue.append(r)
self._plug_idle() self._plug_idle()
def _on_send(self): def _on_send(self):