Handle EINPROGRESS more appropriately (i.e., actually try to work :))

This commit is contained in:
Jeremy Fincher 2004-02-12 00:49:13 +00:00
parent 157106fad6
commit 69671d55a3

View File

@ -41,6 +41,7 @@ import fix
import time import time
import atexit import atexit
import select
import socket import socket
from itertools import imap from itertools import imap
@ -139,17 +140,29 @@ class SocketDriver(drivers.IrcDriver):
self.conn.connect(self.server) self.conn.connect(self.server)
self.conn.settimeout(conf.supybot.drivers.poll()) self.conn.settimeout(conf.supybot.drivers.poll())
except socket.error, e: except socket.error, e:
if e.args[0] != 115: if e.args[0] == 115:
log.warning('Error connecting to %s: %s', self.irc.server, e) 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.reconnect(wait=True)
self.connected = True self.connected = True
self.reconnectWaitPeriodsIndex = 0 self.reconnectWaitPeriodsIndex = 0
def die(self): def _checkAndWriteOrReconnect(self):
log.info('Driver for %s dying.', self.irc) (_, w, _) = select.select([], [self.conn], [], 0)
self.conn.close() if w:
# self.irc.die() Kill off the ircs yourself, jerk! 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): def _scheduleReconnect(self):
when = time.time() + self.reconnectWaits[self.reconnectWaitsIndex] when = time.time() + self.reconnectWaits[self.reconnectWaitsIndex]
when = log.timestamp(when) when = log.timestamp(when)
@ -157,6 +170,11 @@ class SocketDriver(drivers.IrcDriver):
log.info('Scheduling reconnect to %s at %s', self.server, when) log.info('Scheduling reconnect to %s at %s', self.server, when)
schedule.addEvent(self.reconnect, 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): def name(self):
return '%s%s' % (self.__class__.__name__, self.server) return '%s%s' % (self.__class__.__name__, self.server)