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:
parent
f09799f9d9
commit
efaa1a18e7
|
@ -135,7 +135,7 @@ class ChangeStatusCommand(AdHocCommand):
|
|||
|
||||
# if going offline, we need to push response so it won't go into
|
||||
# queue and disappear
|
||||
self.connection.connection.send(response, presencetype == 'offline')
|
||||
self.connection.connection.send(response, now = presencetype == 'offline')
|
||||
|
||||
# send new status
|
||||
gajim.interface.roster.send_status(self.connection.name, presencetype,
|
||||
|
|
|
@ -398,11 +398,11 @@ class Dispatcher(PlugIn):
|
|||
Additional callback arguments can be specified in 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.
|
||||
Returns assigned ID.'''
|
||||
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):
|
||||
_ID=None
|
||||
elif not stanza.getID():
|
||||
|
@ -426,9 +426,9 @@ class Dispatcher(PlugIn):
|
|||
stanza.setNamespace(self._owner.Namespace)
|
||||
stanza.setParent(self._metastream)
|
||||
if is_message:
|
||||
self._owner.Connection.send(stanza, True)
|
||||
self._owner.Connection.send(stanza, True, now = now)
|
||||
else:
|
||||
self._owner.Connection.send(stanza)
|
||||
self._owner.Connection.send(stanza, now = now)
|
||||
return _ID
|
||||
|
||||
def disconnect(self):
|
||||
|
|
|
@ -138,7 +138,7 @@ class SSLWrapper:
|
|||
|
||||
raise NotImplementedException()
|
||||
|
||||
def send(self, data, flags=None):
|
||||
def send(self, data, flags=None, now = False):
|
||||
raise NotImplementedException()
|
||||
|
||||
class PyOpenSSLWrapper(SSLWrapper):
|
||||
|
@ -178,7 +178,7 @@ class PyOpenSSLWrapper(SSLWrapper):
|
|||
raise SSLWrapper.Error(self.sock or self.sslobj, e)
|
||||
return retval
|
||||
|
||||
def send(self, data, flags=None):
|
||||
def send(self, data, flags=None, now = False):
|
||||
try:
|
||||
if flags is None: return self.sslobj.send(data)
|
||||
else: return self.sslobj.send(data, flags)
|
||||
|
@ -219,7 +219,7 @@ class StdlibSSLWrapper(SSLWrapper):
|
|||
raise SSLWrapper.Error(self.sock or self.sslobj, e)
|
||||
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
|
||||
try:
|
||||
return self.sslobj.write(data)
|
||||
|
@ -574,7 +574,7 @@ class NonBlockingTcp(PlugIn, IdleObject):
|
|||
self.on_connect = None
|
||||
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.
|
||||
If supplied data is unicode string, encode it to utf-8.
|
||||
'''
|
||||
|
@ -585,7 +585,11 @@ class NonBlockingTcp(PlugIn, IdleObject):
|
|||
r = r.encode('utf-8')
|
||||
elif not isinstance(r, str):
|
||||
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()
|
||||
|
||||
def _on_send(self):
|
||||
|
|
Loading…
Reference in New Issue