From: Timo Sirainen Date: Wed, 26 Jan 2022 18:10:16 +0000 (+0100) Subject: indexer: Move functions from worker-pool to worker-connection X-Git-Tag: 2.4.0~4435 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=127f0deacd1cc77398b219d8122e72ee80ae0c8d;p=thirdparty%2Fdovecot%2Fcore.git indexer: Move functions from worker-pool to worker-connection --- diff --git a/src/indexer/worker-connection.c b/src/indexer/worker-connection.c index 32e218124e..8c6f38107f 100644 --- a/src/indexer/worker-connection.c +++ b/src/indexer/worker-connection.c @@ -220,3 +220,23 @@ int worker_connection_try_create(const char *socket_path, *conn_r = &conn->conn; return 1; } + +unsigned int worker_connections_get_count(struct connection_list *list) +{ + return list->connections_count; +} + +struct connection * +worker_connections_find_user(struct connection_list *list, + const char *username) +{ + struct connection *conn; + const char *worker_user; + + for (conn = list->connections; conn != NULL; conn = conn->next) { + worker_user = worker_connection_get_username(conn); + if (worker_user != NULL && strcmp(worker_user, username) == 0) + return conn; + } + return NULL; +} diff --git a/src/indexer/worker-connection.h b/src/indexer/worker-connection.h index 1840cbb338..00bab2349d 100644 --- a/src/indexer/worker-connection.h +++ b/src/indexer/worker-connection.h @@ -37,4 +37,9 @@ void worker_connection_request(struct connection *conn, or NULL if there are none. */ const char *worker_connection_get_username(struct connection *conn); +unsigned int worker_connections_get_count(struct connection_list *list); +struct connection * +worker_connections_find_user(struct connection_list *list, + const char *username); + #endif diff --git a/src/indexer/worker-pool.c b/src/indexer/worker-pool.c index 3ebab8c83b..5b667706f8 100644 --- a/src/indexer/worker-pool.c +++ b/src/indexer/worker-pool.c @@ -48,7 +48,7 @@ void worker_pool_deinit(struct worker_pool **_pool) bool worker_pool_have_connections(struct worker_pool *pool) { - return pool->connection_list->connections != NULL; + return worker_connections_get_count(pool->connection_list) > 0; } bool worker_pool_get_connection(struct worker_pool *pool, @@ -63,13 +63,5 @@ struct connection * worker_pool_find_username_connection(struct worker_pool *pool, const char *username) { - struct connection *list; - const char *worker_user; - - for (list = pool->connection_list->connections; list != NULL; list = list->next) { - worker_user = worker_connection_get_username(list); - if (worker_user != NULL && strcmp(worker_user, username) == 0) - return list; - } - return NULL; + return worker_connections_find_user(pool->connection_list, username); }