reconnect: fix callback when not currently connected
The 'disconnected' event is normally fired from connection_lost(), which is called by the connection code when the connection is lost after being established. However, if the connection wasn't successfully established, a manual /reconnect no-ops because it waits for the 'disconnected' callback which never fires. This patch does two things: 1. Immediately fire a 'disconnected' event in disconnect() if there is no transport. 2. Register the 'disconnected' event handler in reconnect() *before* it can be fired.
This commit is contained in:
parent
115c234527
commit
d85efec7a2
1 changed files with 3 additions and 1 deletions
|
@ -494,6 +494,8 @@ class XMLStream(asyncio.BaseProtocol):
|
||||||
self.send_raw(self.stream_footer)
|
self.send_raw(self.stream_footer)
|
||||||
self.schedule('Disconnect wait', wait,
|
self.schedule('Disconnect wait', wait,
|
||||||
self.abort, repeat=False)
|
self.abort, repeat=False)
|
||||||
|
else:
|
||||||
|
self.event("disconnected", reason)
|
||||||
|
|
||||||
def abort(self):
|
def abort(self):
|
||||||
"""
|
"""
|
||||||
|
@ -512,8 +514,8 @@ class XMLStream(asyncio.BaseProtocol):
|
||||||
when the server acknowledgement is received), call connect()
|
when the server acknowledgement is received), call connect()
|
||||||
"""
|
"""
|
||||||
log.debug("reconnecting...")
|
log.debug("reconnecting...")
|
||||||
self.disconnect(wait, reason)
|
|
||||||
self.add_event_handler('disconnected', lambda event: self.connect(), disposable=True)
|
self.add_event_handler('disconnected', lambda event: self.connect(), disposable=True)
|
||||||
|
self.disconnect(wait, reason)
|
||||||
|
|
||||||
def configure_socket(self):
|
def configure_socket(self):
|
||||||
"""Set timeout and other options for self.socket.
|
"""Set timeout and other options for self.socket.
|
||||||
|
|
Loading…
Reference in a new issue