[MAJOR] implementation of the "leastconn" load balancing algorithm

The new "leastconn" LB algorithm selects the server which has the
least established or pending connections. The weights are considered,
so that a server with a weight of 20 will get twice as many connections
as the server with a weight of 10.

The algorithm respects the minconn/maxconn settings, as well as the
slowstart since it is a dynamic algorithm. It also correctly supports
backup servers (one and all).

It is generally suited for protocols with long sessions (such as remote
terminals and databases), as it will ensure that upon restart, a server
with no connection will take all new ones until its load is balanced
with others.

A test configuration has been added in order to ease regression testing.
diff --git a/include/proto/backend.h b/include/proto/backend.h
index 1720105..03fa518 100644
--- a/include/proto/backend.h
+++ b/include/proto/backend.h
@@ -43,6 +43,7 @@
 int be_downtime(struct proxy *px);
 void init_server_map(struct proxy *p);
 void fwrr_init_server_groups(struct proxy *p);
+void fwlc_init_server_tree(struct proxy *p);
 
 /*
  * This function tries to find a running server with free connection slots for
diff --git a/include/types/backend.h b/include/types/backend.h
index 2b35860..2d62722 100644
--- a/include/types/backend.h
+++ b/include/types/backend.h
@@ -2,7 +2,7 @@
   include/types/backend.h
   This file rassembles definitions for backends
 
-  Copyright (C) 2000-2007 Willy Tarreau - w@1wt.eu
+  Copyright (C) 2000-2008 Willy Tarreau - w@1wt.eu
   
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -42,6 +42,7 @@
 #define BE_LB_ALGO_SH	(BE_LB_PROP_L4  | 0x02) /* balance on source IP hash */
 #define BE_LB_ALGO_UH	(BE_LB_PROP_L7  | 0x03) /* balance on URI hash */
 #define BE_LB_ALGO_PH	(BE_LB_PROP_L7  | 0x04) /* balance on URL parameter hash */
+#define BE_LB_ALGO_LC	(BE_LB_PROP_DYN | 0x05) /* fast weighted round-robin mode (dynamic) */
 
 /* various constants */
 
diff --git a/include/types/proxy.h b/include/types/proxy.h
index a2238cb..98baf53 100644
--- a/include/types/proxy.h
+++ b/include/types/proxy.h
@@ -150,9 +150,15 @@
 			struct fwrr_group act;	/* weighted round robin on the active servers */
 			struct fwrr_group bck;	/* weighted round robin on the backup servers */
 		} fwrr;
+		struct {
+			struct eb_root act;	/* weighted least conns on the active servers */
+			struct eb_root bck;	/* weighted least conns on the backup servers */
+		} fwlc;
 		void (*update_server_eweight)(struct server *);/* if non-NULL, to be called after eweight change */
 		void (*set_server_status_up)(struct server *);/* to be called after status changes to UP */
 		void (*set_server_status_down)(struct server *);/* to be called after status changes to DOWN */
+		void (*server_take_conn)(struct server *);/* to be called when connection is assigned */
+		void (*server_drop_conn)(struct server *);/* to be called when connection is dropped */
 	} lbprm;				/* LB parameters for all algorithms */
 
 	char *cookie_name;			/* name of the cookie to look for */