# HG changeset patch # User Timo Sirainen # Date 1103133137 -7200 # Node ID e2876940968e6b10989823f71487d7a9562bbed9 # Parent cad3a8913d4a3a31f0ead78f142fb052e4a123be Connect to available auth sockets by round robin. diff -r cad3a8913d4a -r e2876940968e src/lib-auth/auth-server-connection.c --- 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 { diff -r cad3a8913d4a -r e2876940968e src/lib-auth/auth-server-connection.h --- 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;