Fixed bug in socketDrivers and made it less likely to happen with a fix in drivers.

This commit is contained in:
Jeremy Fincher 2003-09-03 11:06:02 +00:00
parent 25aca81c9a
commit f06a552b73
2 changed files with 25 additions and 11 deletions

View File

@ -69,7 +69,7 @@ class IrcDriver(object):
raise NotImplementedError
def name(self):
return self.__class__.__name__
return repr(self)
class Interactive(IrcDriver):

View File

@ -33,6 +33,8 @@
Contains simple socket drivers. Asyncore bugged (haha, pun!) me.
"""
from __future__ import division
from fix import *
import time
@ -52,8 +54,8 @@ class SocketDriver(drivers.IrcDriver):
global instances
instances += 1
conf.poll = originalPoll / instances
drivers.IrcDriver.__init__(self)
self.server = (server, port)
drivers.IrcDriver.__init__(self) # Must come after server is set.
self.irc = irc
self.irc.driver = self
self.inbuffer = ''
@ -71,8 +73,14 @@ class SocketDriver(drivers.IrcDriver):
del msgs[-1]
self.outbuffer += ''.join(map(str, msgs))
if self.outbuffer:
try:
sent = self.conn.send(self.outbuffer)
self.outbuffer = self.outbuffer[sent:]
except socket.error, e:
# (11, 'Resource temporarily unavailable') raised if connect
# hasn't finished yet.
if e.args[0] != 11:
raise
def run(self):
#debug.methodNamePrintf(self, 'run')
@ -97,6 +105,8 @@ class SocketDriver(drivers.IrcDriver):
except socket.timeout:
pass
except socket.error, e:
# Same as with _sendIfMsgs.
if e.args[0] != 11:
s = 'Disconnect from %s: %s' % (self.server, e.args[1])
debug.msg(s, 'normal')
self.die()
@ -111,11 +121,12 @@ class SocketDriver(drivers.IrcDriver):
self.reconnectWaitsIndex += 1
try:
self.conn.connect(self.server)
self.connected = True
self.reconnectWaitPeriodsIndex = 0
except socket.error, e:
if e.args[0] != 115:
debug.msg('Error connecting to %s: %s' % (self.server, e))
self.die()
self.connected = True
self.reconnectWaitPeriodsIndex = 0
def die(self):
@ -129,6 +140,9 @@ class SocketDriver(drivers.IrcDriver):
'normal')
schedule.addEvent(self.reconnect, when)
def name(self):
return '%s%s' % (self.__class__.__name__, self.server)
Driver = SocketDriver