MEDIUM: sessions: Keep track of which connections are idle.

Instead of keeping track of the number of connections we're responsible for,
keep track of the number of connections we're responsible for that we are
currently considering idling (ie that we are not using, they may be in use
by other sessions), that way we can actually reuse connections when we have
more connections than the max configured.
diff --git a/src/backend.c b/src/backend.c
index b6f08d5..3c1620b 100644
--- a/src/backend.c
+++ b/src/backend.c
@@ -1240,6 +1240,13 @@
 		LIST_ADDQ(&srv->idle_conns[tid], &srv_conn->list);
 		if (LIST_ISEMPTY(&srv->idle_orphan_conns[tid]))
 			task_unlink_wq(srv->idle_task[tid]);
+	} else if (reuse) {
+		if (srv_conn->flags & CO_FL_SESS_IDLE) {
+			struct session *sess = srv_conn->owner;
+
+			srv_conn->flags &= ~CO_FL_SESS_IDLE;
+			sess->idle_conns--;
+		}
 	}
 
 	/* We're about to use another connection, let the mux know we're
@@ -1251,6 +1258,8 @@
 		if (sess) {
 			if (old_conn && !(old_conn->flags & CO_FL_PRIVATE) &&
 			    old_conn->mux != NULL) {
+				if (old_conn->flags & CO_FL_SESS_IDLE)
+					s->sess->idle_conns--;
 				session_unown_conn(s->sess, old_conn);
 				old_conn->owner = sess;
 				if (!session_add_conn(sess, old_conn, s->target)) {