mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 13:19:24 +01:00
Handle EINPROGRESS more appropriately (i.e., actually try to work :))
This commit is contained in:
parent
157106fad6
commit
69671d55a3
@ -41,6 +41,7 @@ import fix
|
||||
|
||||
import time
|
||||
import atexit
|
||||
import select
|
||||
import socket
|
||||
from itertools import imap
|
||||
|
||||
@ -139,17 +140,29 @@ class SocketDriver(drivers.IrcDriver):
|
||||
self.conn.connect(self.server)
|
||||
self.conn.settimeout(conf.supybot.drivers.poll())
|
||||
except socket.error, e:
|
||||
if e.args[0] != 115:
|
||||
log.warning('Error connecting to %s: %s', self.irc.server, e)
|
||||
if e.args[0] == 115:
|
||||
now = time.time()
|
||||
when = now + 60
|
||||
log.info('Connection in progress, scheduling connectedness '
|
||||
'check for %s', when)
|
||||
schedule.addEvent(self._checkAndWriteOrReconnect, when)
|
||||
else:
|
||||
log.warning('Error connecting to %s: %s',
|
||||
self.irc.server, e.args[1])
|
||||
self.reconnect(wait=True)
|
||||
self.connected = True
|
||||
self.reconnectWaitPeriodsIndex = 0
|
||||
|
||||
def die(self):
|
||||
log.info('Driver for %s dying.', self.irc)
|
||||
self.conn.close()
|
||||
# self.irc.die() Kill off the ircs yourself, jerk!
|
||||
|
||||
def _checkAndWriteOrReconnect(self):
|
||||
(_, w, _) = select.select([], [self.conn], [], 0)
|
||||
if w:
|
||||
log.info('Socket is writable, it might be connected.')
|
||||
self.connected = True
|
||||
self.reconnectWaitPeriodsIndex = 0
|
||||
else:
|
||||
log.warning('Error connecting to %s: Timed out.', self.irc.server)
|
||||
self.reconnect()
|
||||
|
||||
def _scheduleReconnect(self):
|
||||
when = time.time() + self.reconnectWaits[self.reconnectWaitsIndex]
|
||||
when = log.timestamp(when)
|
||||
@ -157,6 +170,11 @@ class SocketDriver(drivers.IrcDriver):
|
||||
log.info('Scheduling reconnect to %s at %s', self.server, when)
|
||||
schedule.addEvent(self.reconnect, when)
|
||||
|
||||
def die(self):
|
||||
log.info('Driver for %s dying.', self.irc)
|
||||
self.conn.close()
|
||||
# self.irc.die() Kill off the ircs yourself, jerk!
|
||||
|
||||
def name(self):
|
||||
return '%s%s' % (self.__class__.__name__, self.server)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user