A start on server pooling.
authorEric S. Raymond <esr@thyrsus.com>
Sun, 26 Aug 2012 20:20:22 +0000 (16:20 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Sun, 26 Aug 2012 20:20:22 +0000 (16:20 -0400)
irker.py

index 503b8b4c0ff967fb74c5efd7a435f0f663501ce3..de3b80a056519f09a01545e6341b46d0e6e0a324 100755 (executable)
--- a/irker.py
+++ b/irker.py
@@ -68,10 +68,11 @@ class Session():
             # expires, then reconnect and resume transmission if the
             # queue fills up again.
             if not self.server:
-                self.server = self.irker.irc.server()
+                self.server = self.irker.allocate_server(self.servername,
+                                                         self.port,
+                                                         self.name())
                 self.irker.debug(1, "TTL bump (connection) at %s" % time.asctime())
                 self.last_active = time.time()
-                self.server.connect(self.servername, self.port, self.name())
             elif self.queue.empty():
                 if time.time() > self.last_active + TTL:
                     self.irker.debug(1, "timing out inactive connection at %s" % time.asctime())
@@ -109,6 +110,11 @@ class Irker:
         "Debugging information."
         if self.debuglevel >= level:
             sys.stderr.write("irker[%d]: %s\n" % (self.debuglevel, errmsg))
+    def allocate_server(self, servername, port, nick):
+        "Allocate a new server instance."
+        newserver = self.irc.server()
+        newserver.connect(servername, port, nick)
+        return newserver
     def handle(self, line):
         "Perform a JSON relay request."
         try: