Skip to content
Snippets Groups Projects
Commit 3e0020e4 authored by Eric S. Raymond's avatar Eric S. Raymond
Browse files

Channel timeout appears to work.

parent 68ede3c4
No related branches found
No related tags found
No related merge requests found
...@@ -20,7 +20,7 @@ TO-DO: Multiple irkers could try to use the same nick ...@@ -20,7 +20,7 @@ TO-DO: Multiple irkers could try to use the same nick
HOST = "localhost" HOST = "localhost"
PORT = 4747 PORT = 4747
TTL = 30 # Connection time to live in seconds TTL = (3 * 60 * 60) # Connection time to live in seconds
# No user-serviceable parts below this line # No user-serviceable parts below this line
...@@ -34,7 +34,7 @@ class SessionException(exceptions.Exception): ...@@ -34,7 +34,7 @@ class SessionException(exceptions.Exception):
class Session(): class Session():
"IRC session and message queue processing." "IRC session and message queue processing."
count = 1 count = 0
def __init__(self, irker, url): def __init__(self, irker, url):
self.irker = irker self.irker = irker
self.url = url self.url = url
...@@ -59,7 +59,7 @@ class Session(): ...@@ -59,7 +59,7 @@ class Session():
def dequeue(self): def dequeue(self):
"Try to ship pending messages from the queue." "Try to ship pending messages from the queue."
while True: while True:
# We want to by kind to the servers and not hold unused # We want to be kind to the IRC servers and not hold unused
# sockets open forever, so they have a time-to-live. The # sockets open forever, so they have a time-to-live. The
# loop is coded this particular way so that we can drop # loop is coded this particular way so that we can drop
# the actual server connection when its time-to-live # the actual server connection when its time-to-live
...@@ -67,11 +67,13 @@ class Session(): ...@@ -67,11 +67,13 @@ class Session():
# queue fills up again. # queue fills up again.
if not self.server: if not self.server:
self.server = self.irker.irc.server() self.server = self.irker.irc.server()
self.server.connect(self.servername, self.port, self.name()) self.irker.debug(1, "TTL bump (connection) at %s" % time.asctime())
self.last_active = time.time() self.last_active = time.time()
self.server.connect(self.servername, self.port, self.name())
elif self.queue.empty(): elif self.queue.empty():
if time.time() > self.last_active + TTL: if time.time() > self.last_active + TTL:
self.server.part("#" + channel) self.irker.debug(1, "timing out inactive connection at %s" % time.asctime())
self.server.part("#" + self.channel)
self.server = None self.server = None
break break
else: else:
...@@ -79,6 +81,7 @@ class Session(): ...@@ -79,6 +81,7 @@ class Session():
self.server.join("#" + self.channel) self.server.join("#" + self.channel)
self.server.privmsg("#" + self.channel, message) self.server.privmsg("#" + self.channel, message)
self.last_active = time.time() self.last_active = time.time()
self.irker.debug(1, "TTL bump (transmission) at %s" % time.asctime())
self.queue.task_done() self.queue.task_done()
def name(self): def name(self):
"Generate a unique name for this session." "Generate a unique name for this session."
...@@ -142,6 +145,7 @@ if __name__ == '__main__': ...@@ -142,6 +145,7 @@ if __name__ == '__main__':
server = SocketServer.TCPServer((host, port), MyTCPHandler) server = SocketServer.TCPServer((host, port), MyTCPHandler)
try: try:
server.serve_forever() server.serve_forever()
except keyboardInterrupt: except KeyboardInterrupt:
pass pass
# end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment