mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-30 14:59:34 +01:00
Fixed bug in socketDrivers and made it less likely to happen with a fix in drivers.
This commit is contained in:
parent
25aca81c9a
commit
f06a552b73
@ -69,7 +69,7 @@ class IrcDriver(object):
|
|||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def name(self):
|
def name(self):
|
||||||
return self.__class__.__name__
|
return repr(self)
|
||||||
|
|
||||||
|
|
||||||
class Interactive(IrcDriver):
|
class Interactive(IrcDriver):
|
||||||
|
@ -33,6 +33,8 @@
|
|||||||
Contains simple socket drivers. Asyncore bugged (haha, pun!) me.
|
Contains simple socket drivers. Asyncore bugged (haha, pun!) me.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import division
|
||||||
|
|
||||||
from fix import *
|
from fix import *
|
||||||
|
|
||||||
import time
|
import time
|
||||||
@ -52,8 +54,8 @@ class SocketDriver(drivers.IrcDriver):
|
|||||||
global instances
|
global instances
|
||||||
instances += 1
|
instances += 1
|
||||||
conf.poll = originalPoll / instances
|
conf.poll = originalPoll / instances
|
||||||
drivers.IrcDriver.__init__(self)
|
|
||||||
self.server = (server, port)
|
self.server = (server, port)
|
||||||
|
drivers.IrcDriver.__init__(self) # Must come after server is set.
|
||||||
self.irc = irc
|
self.irc = irc
|
||||||
self.irc.driver = self
|
self.irc.driver = self
|
||||||
self.inbuffer = ''
|
self.inbuffer = ''
|
||||||
@ -71,8 +73,14 @@ class SocketDriver(drivers.IrcDriver):
|
|||||||
del msgs[-1]
|
del msgs[-1]
|
||||||
self.outbuffer += ''.join(map(str, msgs))
|
self.outbuffer += ''.join(map(str, msgs))
|
||||||
if self.outbuffer:
|
if self.outbuffer:
|
||||||
sent = self.conn.send(self.outbuffer)
|
try:
|
||||||
self.outbuffer = self.outbuffer[sent:]
|
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):
|
def run(self):
|
||||||
#debug.methodNamePrintf(self, 'run')
|
#debug.methodNamePrintf(self, 'run')
|
||||||
@ -97,9 +105,11 @@ class SocketDriver(drivers.IrcDriver):
|
|||||||
except socket.timeout:
|
except socket.timeout:
|
||||||
pass
|
pass
|
||||||
except socket.error, e:
|
except socket.error, e:
|
||||||
s = 'Disconnect from %s: %s' % (self.server, e.args[1])
|
# Same as with _sendIfMsgs.
|
||||||
debug.msg(s, 'normal')
|
if e.args[0] != 11:
|
||||||
self.die()
|
s = 'Disconnect from %s: %s' % (self.server, e.args[1])
|
||||||
|
debug.msg(s, 'normal')
|
||||||
|
self.die()
|
||||||
return
|
return
|
||||||
self._sendIfMsgs()
|
self._sendIfMsgs()
|
||||||
|
|
||||||
@ -111,11 +121,12 @@ class SocketDriver(drivers.IrcDriver):
|
|||||||
self.reconnectWaitsIndex += 1
|
self.reconnectWaitsIndex += 1
|
||||||
try:
|
try:
|
||||||
self.conn.connect(self.server)
|
self.conn.connect(self.server)
|
||||||
self.connected = True
|
|
||||||
self.reconnectWaitPeriodsIndex = 0
|
|
||||||
except socket.error, e:
|
except socket.error, e:
|
||||||
debug.msg('Error connecting to %s: %s' % (self.server, e))
|
if e.args[0] != 115:
|
||||||
self.die()
|
debug.msg('Error connecting to %s: %s' % (self.server, e))
|
||||||
|
self.die()
|
||||||
|
self.connected = True
|
||||||
|
self.reconnectWaitPeriodsIndex = 0
|
||||||
|
|
||||||
|
|
||||||
def die(self):
|
def die(self):
|
||||||
@ -129,6 +140,9 @@ class SocketDriver(drivers.IrcDriver):
|
|||||||
'normal')
|
'normal')
|
||||||
schedule.addEvent(self.reconnect, when)
|
schedule.addEvent(self.reconnect, when)
|
||||||
|
|
||||||
|
def name(self):
|
||||||
|
return '%s%s' % (self.__class__.__name__, self.server)
|
||||||
|
|
||||||
|
|
||||||
Driver = SocketDriver
|
Driver = SocketDriver
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user