Efficiency fix.
authorEric S. Raymond <esr@thyrsus.com>
Fri, 5 Oct 2012 14:11:39 +0000 (10:11 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Fri, 5 Oct 2012 14:11:39 +0000 (10:11 -0400)
irkerd

diff --git a/irkerd b/irkerd
index 042ae29cdd48794a0336bf2fbffdbf75ee5fdc0f..37a28a6fac2585d07e54397cca31637487ce909f 100755 (executable)
--- a/irkerd
+++ b/irkerd
@@ -174,28 +174,7 @@ class Connection:
                 # the actual server connection when its time-to-live
                 # expires, then reconnect and resume transmission if the
                 # queue fills up again.
-                if not self.connection:
-                    self.connection = self.irker.irc.server()
-                    self.connection.context = self
-                    # Try to avoid colliding with other instances
-                    self.nick_trial = random.randint(1, 990)
-                    self.channels_joined = []
-                    # This will throw irc.client.ServerConnectionError on failure
-                    try:
-                        self.connection.connect(self.servername,
-                                            self.port,
-                                            nickname=self.nickname(),
-                                            username="irker",
-                                            ircname="irker relaying client")
-                        self.status = "handshaking"
-                        self.irker.debug(1, "XMIT_TTL bump (%s connection) at %s" % (self.servername, time.asctime()))
-                        self.last_xmit = time.time()
-                    except irc.client.ServerConnectionError:
-                        self.status = "disconnected"
-                elif self.status == "handshaking":
-                    # Don't buzz on the empty-queue test while we're handshaking 
-                    time.sleep(ANTI_BUZZ_DELAY)
-                elif self.queue.empty():
+                if self.queue.empty():
                     # Queue is empty, at some point we want to time out
                     # the connection rather than holding a socket open in
                     # the server forever.
@@ -216,6 +195,29 @@ class Connection:
                         # reflex arc it is highly unlikely any human will ever
                         # notice.
                         time.sleep(ANTI_BUZZ_DELAY)
+                elif not self.connection:
+                    # Queue is nonempty but server isn't connected.
+                    self.connection = self.irker.irc.server()
+                    self.connection.context = self
+                    # Try to avoid colliding with other instances
+                    self.nick_trial = random.randint(1, 990)
+                    self.channels_joined = []
+                    # This will throw irc.client.ServerConnectionError on failure
+                    try:
+                        self.connection.connect(self.servername,
+                                            self.port,
+                                            nickname=self.nickname(),
+                                            username="irker",
+                                            ircname="irker relaying client")
+                        self.status = "handshaking"
+                        self.irker.debug(1, "XMIT_TTL bump (%s connection) at %s" % (self.servername, time.asctime()))
+                        self.last_xmit = time.time()
+                    except irc.client.ServerConnectionError:
+                        self.status = "disconnected"
+                elif self.status == "handshaking":
+                    # Don't buzz on the empty-queue test while we're
+                    # handshaking
+                    time.sleep(ANTI_BUZZ_DELAY)
                 elif self.status == "disconnected" \
                          and time.time() > self.last_xmit + DISCONNECT_TTL:
                     # Queue is nonempty, but the IRC server might be