changeset 2970:e2876940968e HEAD

Connect to available auth sockets by round robin.
author Timo Sirainen <tss@iki.fi>
date Wed, 15 Dec 2004 19:52:17 +0200
parents cad3a8913d4a
children 1f7bcbb09f90
files src/lib-auth/auth-server-connection.c src/lib-auth/auth-server-connection.h
diffstat 2 files changed, 23 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-auth/auth-server-connection.c	Wed Dec 15 19:44:22 2004 +0200
+++ b/src/lib-auth/auth-server-connection.c	Wed Dec 15 19:52:17 2004 +0200
@@ -321,18 +321,35 @@
 auth_server_connection_find_mech(struct auth_client *client,
 				 const char *name, const char **error_r)
 {
-	struct auth_server_connection *conn;
+	struct auth_server_connection *conn, *match;
 	const struct auth_mech_desc *mech;
-	unsigned int i;
+	unsigned int i, n, match_n;
 
-	for (conn = client->connections; conn != NULL; conn = conn->next) {
+	/* find a connection which has this mechanism. if there are multiple
+	   available connections to use, do round robin load balancing */
+	match = NULL; match_n = n = 0;
+	for (conn = client->connections; conn != NULL; conn = conn->next, n++) {
 		mech = conn->available_auth_mechs;
 		for (i = 0; i < conn->available_auth_mechs_count; i++) {
-			if (strcasecmp(mech[i].name, name) == 0)
-				return conn;
+			if (strcasecmp(mech[i].name, name) == 0) {
+				if (n > client->last_used_auth_process) {
+					client->last_used_auth_process = n;
+					return conn;
+				}
+				if (match == NULL) {
+					match = conn;
+					match_n = n;
+				}
+				break;
+			}
 		}
 	}
 
+	if (match != NULL) {
+		client->last_used_auth_process = match_n;
+		return match;
+	}
+
 	if (auth_client_find_mech(client, name) == NULL)
 		*error_r = "Unsupported authentication mechanism";
 	else {
--- a/src/lib-auth/auth-server-connection.h	Wed Dec 15 19:44:22 2004 +0200
+++ b/src/lib-auth/auth-server-connection.h	Wed Dec 15 19:52:17 2004 +0200
@@ -15,6 +15,7 @@
 
 	buffer_t *available_auth_mechs;
 	unsigned int request_id_counter;
+	unsigned int last_used_auth_process;
 
 	auth_connect_notify_callback_t *connect_notify_callback;
 	void *connect_notify_context;