Monitor state of all connections, and utility of all servers.

def __audit_connections(self, ccallbacks):
        """Monitor state of all connections, and utility of all servers."""

        while self.__quit_ev.is_set() is False:
            # Remove any connections that are dead.
            self.__connections = filter(
                                    lambda (n, c, g): not g.ready(), 
                                    self.__connections)

            connected_node_couplets_s = set([
                (c.managed_connection.context, node)
                for (node, c, g) 
                in self.__connections])

            # Warn if there are any still-active connections that are no longer 
            # being advertised (probably where we were given some lookup servers 
            # that have dropped this particular *nsqd* server).

            lingering_nodes_s = connected_node_couplets_s - \
                                self.__node_couplets_s

            if lingering_nodes_s:
                _logger.warning("Server(s) are connected but no longer "
                                "advertised: %s", lingering_nodes_s)

            # Connect any servers that don't currently have a connection.

            unused_nodes_s = self.__node_couplets_s - connected_node_couplets_s

            for (context, node) in unused_nodes_s:
                _logger.info("Trying to connect unconnected server: "
                             "CONTEXT=[%s] NODE=[%s]", context, node)

                self.__start_connection(context, node, ccallbacks)
            else:
                # Are there both no unused servers and no connected servers?
                if not connected_node_couplets_s:
                    _logger.error("All servers have gone away. Stopping "
                                  "client.")

                    # Clear our list of servers, and squash the "no servers!" 
                    # error so that we can shut things down in the right order.

                    try:
                        self.set_servers([])
                    except EnvironmentError:
                        pass

                    self.__quit_ev.set()
                    return

            interval_s = \
                nsq.config.client.GRANULAR_CONNECTION_AUDIT_SLEEP_STEP_TIME_S

            audit_wait_s = float(nsq.config.client.CONNECTION_AUDIT_WAIT_S)

            while audit_wait_s > 0 and\
                  self.__quit_ev.is_set() is False:
                gevent.sleep(interval_s)
                audit_wait_s -= interval_s