mirror of
https://github.com/jlu5/PyLink.git
synced 2025-01-25 19:54:25 +01:00
Irc: move PYLINK_DISCONNECT firing and connected.clear() into disconnect() (#421)
This may prevent extra irc.connected.clear() calls from messing with the was_connected state.
This commit is contained in:
parent
6fcb129ad6
commit
4df8567fa6
10
classes.py
10
classes.py
@ -105,7 +105,6 @@ class Irc():
|
|||||||
self.pingfreq = self.serverdata.get('pingfreq') or 90
|
self.pingfreq = self.serverdata.get('pingfreq') or 90
|
||||||
self.pingtimeout = self.pingfreq * 3
|
self.pingtimeout = self.pingfreq * 3
|
||||||
|
|
||||||
self.connected.clear()
|
|
||||||
self.pseudoclient = None
|
self.pseudoclient = None
|
||||||
self.lastping = time.time()
|
self.lastping = time.time()
|
||||||
|
|
||||||
@ -319,12 +318,8 @@ class Irc():
|
|||||||
log.error('(%s) Disconnected from IRC: %s: %s',
|
log.error('(%s) Disconnected from IRC: %s: %s',
|
||||||
self.name, type(e).__name__, str(e))
|
self.name, type(e).__name__, str(e))
|
||||||
|
|
||||||
was_successful = self.connected.is_set()
|
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
|
|
||||||
# Internal hook signifying that a network has disconnected.
|
|
||||||
self.callHooks([None, 'PYLINK_DISCONNECT', {'was_successful': checks_ok and was_successful}])
|
|
||||||
|
|
||||||
# If autoconnect is enabled, loop back to the start. Otherwise,
|
# If autoconnect is enabled, loop back to the start. Otherwise,
|
||||||
# return and stop.
|
# return and stop.
|
||||||
autoconnect = self.serverdata.get('autoconnect')
|
autoconnect = self.serverdata.get('autoconnect')
|
||||||
@ -343,6 +338,8 @@ class Irc():
|
|||||||
|
|
||||||
def disconnect(self):
|
def disconnect(self):
|
||||||
"""Handle disconnects from the remote server."""
|
"""Handle disconnects from the remote server."""
|
||||||
|
was_successful = self.connected.is_set()
|
||||||
|
log.debug('(%s) disconnect: got %s for was_successful state', self.name, was_successful)
|
||||||
|
|
||||||
log.debug('(%s) disconnect: Clearing self.connected state.', self.name)
|
log.debug('(%s) disconnect: Clearing self.connected state.', self.name)
|
||||||
self.connected.clear()
|
self.connected.clear()
|
||||||
@ -366,6 +363,9 @@ class Irc():
|
|||||||
log.debug('(%s) disconnect: Setting self.aborted to True.', self.name)
|
log.debug('(%s) disconnect: Setting self.aborted to True.', self.name)
|
||||||
self.aborted.set()
|
self.aborted.set()
|
||||||
|
|
||||||
|
# Internal hook signifying that a network has disconnected.
|
||||||
|
self.callHooks([None, 'PYLINK_DISCONNECT', {'was_successful': was_successful}])
|
||||||
|
|
||||||
log.debug('(%s) disconnect: Clearing state via initVars().', self.name)
|
log.debug('(%s) disconnect: Clearing state via initVars().', self.name)
|
||||||
self.initVars()
|
self.initVars()
|
||||||
|
|
||||||
|
@ -1509,9 +1509,11 @@ def handle_disconnect(irc, numeric, command, args):
|
|||||||
|
|
||||||
# Announce the disconnects to every leaf channel where the disconnected network is the owner
|
# Announce the disconnects to every leaf channel where the disconnected network is the owner
|
||||||
announcement = conf.conf.get('relay', {}).get('disconnect_announcement')
|
announcement = conf.conf.get('relay', {}).get('disconnect_announcement')
|
||||||
|
log.debug('(%s) relay: last connection successful: %s', irc.name, args.get('was_successful'))
|
||||||
if announcement and args.get('was_successful'):
|
if announcement and args.get('was_successful'):
|
||||||
with db_lock:
|
with db_lock:
|
||||||
for chanpair, entrydata in db.items():
|
for chanpair, entrydata in db.items():
|
||||||
|
log.debug('(%s) relay: Looking up %s', irc.name, chanpair)
|
||||||
if chanpair[0] == irc.name:
|
if chanpair[0] == irc.name:
|
||||||
for leaf in entrydata['links']:
|
for leaf in entrydata['links']:
|
||||||
log.debug('(%s) relay: Announcing disconnect to %s%s', irc.name,
|
log.debug('(%s) relay: Announcing disconnect to %s%s', irc.name,
|
||||||
|
Loading…
Reference in New Issue
Block a user