#include "lib.h"
#include "ioloop.h"
#include "llist.h"
+#include "connection.h"
#include "master-service.h"
#include "worker-connection.h"
#include "worker-pool.h"
#define MAX_WORKER_IDLE_SECS (60*5)
-struct worker_connection_list {
- struct worker_connection_list *prev, *next;
-
- struct connection *conn;
-};
-
struct worker_pool {
char *socket_path;
indexer_status_callback_t *callback;
unsigned int connection_count;
- struct worker_connection_list *busy_list;
+ struct connection_list connection_list;
};
static void
worker_connection_list_free(struct worker_pool *pool,
- struct worker_connection_list *list);
+ struct connection *list);
struct worker_pool *
worker_pool_init(const char *socket_path, indexer_status_callback_t *callback)
*_pool = NULL;
- while (pool->busy_list != NULL) {
- struct worker_connection_list *list = pool->busy_list;
+ while (pool->connection_list.connections != NULL) {
+ struct connection *list = pool->connection_list.connections;
- DLLIST_REMOVE(&pool->busy_list, list);
+ DLLIST_REMOVE(&pool->connection_list.connections, list);
worker_connection_list_free(pool, list);
}
bool worker_pool_have_busy_connections(struct worker_pool *pool)
{
- return pool->busy_list != NULL;
+ return pool->connection_list.connections != NULL;
}
static int worker_pool_add_connection(struct worker_pool *pool,
static void
worker_connection_list_free(struct worker_pool *pool,
- struct worker_connection_list *list)
+ struct connection *list)
{
i_assert(pool->connection_count > 0);
pool->connection_count--;
- worker_connection_destroy(&list->conn);
- i_free(list);
+ worker_connection_destroy(&list);
}
static unsigned int worker_pool_find_max_connections(struct worker_pool *pool)
{
- struct worker_connection_list *list;
+ struct connection *list;
unsigned int limit;
- if (pool->busy_list == NULL)
+ if (pool->connection_list.connections == NULL)
return 1;
- for (list = pool->busy_list; list != NULL; list = list->next) {
- if (worker_connection_get_process_limit(list->conn, &limit))
+ for (list = pool->connection_list.connections; list != NULL; list = list->next) {
+ if (worker_connection_get_process_limit(list, &limit))
return limit;
}
/* we have at least one connection that has already been created,
bool worker_pool_get_connection(struct worker_pool *pool,
struct connection **conn_r)
{
- struct worker_connection_list *list;
unsigned int max_connections;
max_connections = worker_pool_find_max_connections(pool);
return FALSE;
if (worker_pool_add_connection(pool, conn_r) < 0)
return FALSE;
- list = i_new(struct worker_connection_list, 1);
- list->conn = *conn_r;
- DLLIST_PREPEND(&pool->busy_list, list);
+ DLLIST_PREPEND(&pool->connection_list.connections, *conn_r);
return TRUE;
}
void worker_pool_release_connection(struct worker_pool *pool,
struct connection *conn)
{
- struct worker_connection_list *list;
+ struct connection *list;
pool->connection_count--;
- for (list = pool->busy_list; list != NULL; list = list->next) {
- if (list->conn == conn)
+ for (list = pool->connection_list.connections; list != NULL; list = list->next) {
+ if (list == conn)
break;
}
i_assert(list != NULL);
- DLLIST_REMOVE(&pool->busy_list, list);
+ DLLIST_REMOVE(&pool->connection_list.connections, list);
worker_connection_destroy(&conn);
}
worker_pool_find_username_connection(struct worker_pool *pool,
const char *username)
{
- struct worker_connection_list *list;
+ struct connection *list;
const char *worker_user;
- for (list = pool->busy_list; list != NULL; list = list->next) {
- worker_user = worker_connection_get_username(list->conn);
+ 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->conn;
+ return list;
}
return NULL;
}