Tried to fix0r the bugz0r that wishy and I are having with failures to reconnect.

This commit is contained in:
Jeremy Fincher 2004-02-17 01:45:30 +00:00
parent f14341ef26
commit c809cc9217

View File

@ -71,6 +71,7 @@ class SocketDriver(drivers.IrcDriver):
self.inbuffer = '' self.inbuffer = ''
self.outbuffer = '' self.outbuffer = ''
self.connected = False self.connected = False
self.eagains = 0
self.reconnectWaitsIndex = 0 self.reconnectWaitsIndex = 0
self.reconnectWaits = reconnectWaits self.reconnectWaits = reconnectWaits
self.reconnect() self.reconnect()
@ -85,12 +86,16 @@ class SocketDriver(drivers.IrcDriver):
try: try:
sent = self.conn.send(self.outbuffer) sent = self.conn.send(self.outbuffer)
self.outbuffer = self.outbuffer[sent:] self.outbuffer = self.outbuffer[sent:]
self.eagains = 0
except socket.error, e: except socket.error, e:
# (11, 'Resource temporarily unavailable') raised if connect # (11, 'Resource temporarily unavailable') raised if connect
# hasn't finished yet. # hasn't finished yet.
if e.args[0] != 11: if e.args[0] != 11 and self.eagains > 120:
log.warning('Disconnect from %s: %s', self.server, e) log.warning('Disconnect from %s: %s', self.server, e)
self.reconnect(wait=True) self.reconnect(wait=True)
else:
log.debug('Got EAGAIN, current count: %s', self.eagains)
self.eagains += 1
def run(self): def run(self):
if not self.connected: if not self.connected:
@ -101,6 +106,7 @@ class SocketDriver(drivers.IrcDriver):
self._sendIfMsgs() self._sendIfMsgs()
try: try:
self.inbuffer += self.conn.recv(1024) self.inbuffer += self.conn.recv(1024)
self.eagains = 0
lines = self.inbuffer.split('\n') lines = self.inbuffer.split('\n')
self.inbuffer = lines.pop() self.inbuffer = lines.pop()
for line in lines: for line in lines:
@ -115,9 +121,12 @@ class SocketDriver(drivers.IrcDriver):
pass pass
except socket.error, e: except socket.error, e:
# Same as with _sendIfMsgs. # Same as with _sendIfMsgs.
if e.args[0] != 11: if e.args[0] != 11 or self.eagains > 120:
log.warning('Disconnect from %s: %s', self.server, e) log.warning('Disconnect from %s: %s', self.server, e)
self.reconnect(wait=True) self.reconnect(wait=True)
else:
log.debug('Got EAGAIN, current count: %s', self.eagains)
self.eagains += 1
return return
self._sendIfMsgs() self._sendIfMsgs()