Fixed reconnects.

This commit is contained in:
Jeremy Fincher 2003-04-19 23:51:26 +00:00
parent ee74036505
commit dc8b430754

View File

@ -27,7 +27,7 @@ class SupyIrcProtocol(LineReceiver):
delimiter = '\n' delimiter = '\n'
MAX_LENGTH = 1024 MAX_LENGTH = 1024
def __init__(self): def __init__(self):
reactor.callLater(1, self.checkIrcForMsgs) self.mostRecentCall = reactor.callLater(1, self.checkIrcForMsgs)
def lineReceived(self, line): def lineReceived(self, line):
start = time.time() start = time.time()
@ -42,22 +42,28 @@ class SupyIrcProtocol(LineReceiver):
def checkIrcForMsgs(self): def checkIrcForMsgs(self):
if self.connected: if self.connected:
msg = self.factory.irc.takeMsg() msg = self.factory.irc.takeMsg()
while msg: if msg:
self.transport.write(str(msg)) self.transport.write(str(msg))
msg = self.factory.irc.takeMsg()
self.mostRecentCall = reactor.callLater(1, self.checkIrcForMsgs) self.mostRecentCall = reactor.callLater(1, self.checkIrcForMsgs)
def connectionLost(self): def connectionLost(self):
self.mostRecentCall.cancel() self.mostRecentCall.cancel()
def connectionMade(self):
self.factory.irc.driver = self
self.factory.irc.reset()
#self.mostRecentCall = reactor.callLater(1, self.checkIrcForMsgs)
def die(self): def die(self):
self.transport.loseConnection() self.transport.loseConnection()
class SupyReconnectingFactory(ReconnectingClientFactory): class SupyReconnectingFactory(ReconnectingClientFactory):
maxDelay = 600 maxDelay = 600
protocol = SupyIrcProtocol protocol = SupyIrcProtocol
def __init__(self, (server, port), irc): def __init__(self, (server, port), irc):
self.irc = irc self.irc = irc
self.server = (server, port)
reactor.connectTCP(server, port, self) reactor.connectTCP(server, port, self)
@ -83,6 +89,8 @@ if conf.telnetEnable and __name__ != '__main__':
reactor.listenTCP(conf.telnetPort, MyShellFactory()) reactor.listenTCP(conf.telnetPort, MyShellFactory())
Driver = SupyReconnectingFactory
try: try:
ignore(poller) ignore(poller)
except NameError: except NameError: