"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/indexer/worker-pool.c" between
dovecot-2.3.16.tar.gz and dovecot-2.3.17.tar.gz

About: Dovecot is an IMAP and POP3 server, written with security primarily in mind.

worker-pool.c  (dovecot-2.3.16):worker-pool.c  (dovecot-2.3.17)
skipping to change at line 16 skipping to change at line 16
#include "connection.h" #include "connection.h"
#include "master-service.h" #include "master-service.h"
#include "worker-connection.h" #include "worker-connection.h"
#include "worker-pool.h" #include "worker-pool.h"
#define MAX_WORKER_IDLE_SECS (60*5) #define MAX_WORKER_IDLE_SECS (60*5)
struct worker_pool { struct worker_pool {
char *socket_path; char *socket_path;
indexer_status_callback_t *callback; indexer_status_callback_t *callback;
worker_available_callback_t *avail_callback;
struct connection_list *connection_list; struct connection_list *connection_list;
}; };
struct worker_pool * struct worker_pool *
worker_pool_init(const char *socket_path, indexer_status_callback_t *callback) worker_pool_init(const char *socket_path, indexer_status_callback_t *callback,
worker_available_callback_t *avail_callback)
{ {
struct worker_pool *pool; struct worker_pool *pool;
pool = i_new(struct worker_pool, 1); pool = i_new(struct worker_pool, 1);
pool->socket_path = i_strdup(socket_path); pool->socket_path = i_strdup(socket_path);
pool->callback = callback; pool->callback = callback;
pool->avail_callback = avail_callback;
pool->connection_list = worker_connection_list_create(); pool->connection_list = worker_connection_list_create();
return pool; return pool;
} }
void worker_pool_deinit(struct worker_pool **_pool) void worker_pool_deinit(struct worker_pool **_pool)
{ {
struct worker_pool *pool = *_pool; struct worker_pool *pool = *_pool;
*_pool = NULL; *_pool = NULL;
if (pool->connection_list != NULL) if (pool->connection_list != NULL)
connection_list_deinit(&pool->connection_list); connection_list_deinit(&pool->connection_list);
i_free(pool->connection_list); i_free(pool->connection_list);
i_free(pool->socket_path); i_free(pool->socket_path);
i_free(pool); i_free(pool);
} }
bool worker_pool_have_busy_connections(struct worker_pool *pool) bool worker_pool_have_connections(struct worker_pool *pool)
{ {
struct connection *list; return pool->connection_list->connections != NULL;
for (list = pool->connection_list->connections; list != NULL; list = list
->next)
if (worker_connection_is_busy(list))
return TRUE;
return FALSE;
} }
static int worker_pool_add_connection(struct worker_pool *pool, static int worker_pool_add_connection(struct worker_pool *pool,
struct connection **conn_r) struct connection **conn_r)
{ {
struct connection *conn; struct connection *conn;
conn = worker_connection_create(pool->socket_path, pool->callback, conn = worker_connection_create(pool->socket_path, pool->callback,
pool->avail_callback,
pool->connection_list); pool->connection_list);
if (connection_client_connect(conn) < 0) { if (connection_client_connect(conn) < 0) {
worker_connection_unref(&conn); worker_connection_destroy(conn);
return -1; return -1;
} }
*conn_r = conn; *conn_r = conn;
return 0; return 0;
} }
static unsigned int worker_pool_find_max_connections(struct worker_pool *pool)
{
struct connection *list;
unsigned int limit;
if (pool->connection_list->connections == NULL)
return 1;
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,
but without having handshaked yet. wait until it's finished. */
return 0;
}
bool worker_pool_get_connection(struct worker_pool *pool, bool worker_pool_get_connection(struct worker_pool *pool,
struct connection **conn_r) struct connection **conn_r)
{ {
unsigned int max_connections; unsigned int max_connections;
max_connections = worker_pool_find_max_connections(pool); max_connections = I_MAX(1, worker_connections_get_process_limit());
if (pool->connection_list->connections_count >= max_connections) if (pool->connection_list->connections_count >= max_connections)
return FALSE; return FALSE;
if (worker_pool_add_connection(pool, conn_r) < 0) if (worker_pool_add_connection(pool, conn_r) < 0)
return FALSE; return FALSE;
return TRUE; return TRUE;
} }
void worker_pool_release_connection(struct worker_pool *pool ATTR_UNUSED,
struct connection *conn)
{
worker_connection_unref(&conn);
}
struct connection * struct connection *
worker_pool_find_username_connection(struct worker_pool *pool, worker_pool_find_username_connection(struct worker_pool *pool,
const char *username) const char *username)
{ {
struct connection *list; struct connection *list;
const char *worker_user; const char *worker_user;
for (list = pool->connection_list->connections; list != NULL; list = list ->next) { for (list = pool->connection_list->connections; list != NULL; list = list ->next) {
worker_user = worker_connection_get_username(list); worker_user = worker_connection_get_username(list);
if (worker_user != NULL && strcmp(worker_user, username) == 0) if (worker_user != NULL && strcmp(worker_user, username) == 0)
 End of changes. 10 change blocks. 
34 lines changed or deleted 9 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)