char *request_username;
struct indexer_request *request;
-
- unsigned int process_limit;
};
+static unsigned int worker_last_process_limit = 0;
+
static void worker_connection_call_callback(struct worker_connection *worker,
int percentage)
{
static int
worker_connection_handshake_args(struct connection *conn, const char *const *args)
{
- struct worker_connection *worker =
- container_of(conn, struct worker_connection, conn);
+ unsigned int process_limit;
int ret;
if (!conn->version_received) {
if ((ret = connection_handshake_args_default(conn, args)) < 1)
/* we are not done yet */
return 0;
}
- i_assert(worker->process_limit == 0);
- if (str_to_uint(args[0], &worker->process_limit) < 0 ||
- worker->process_limit == 0) {
+ if (str_to_uint(args[0], &process_limit) < 0 ||
+ process_limit == 0) {
e_error(conn->event, "Worker sent invalid process limit '%s'",
args[0]);
return -1;
}
+ worker_last_process_limit = process_limit;
return 1;
}
return !conn->disconnected;
}
-bool worker_connection_get_process_limit(struct connection *conn,
- unsigned int *limit_r)
+unsigned int worker_connections_get_process_limit(void)
{
- struct worker_connection *worker =
- container_of(conn, struct worker_connection, conn);
-
- if (worker->process_limit == 0)
- return FALSE;
-
- *limit_r = worker->process_limit;
- return TRUE;
+ return worker_last_process_limit;
}
void worker_connection_request(struct connection *conn,
/* Returns TRUE if worker is connected to (not necessarily handshaked yet) */
bool worker_connection_is_connected(struct connection *conn);
-/* After initial handshake the worker process tells how many of its kind
- can be at maximum. This returns the value, of FALSE if handshake isn't
- finished yet. */
-bool worker_connection_get_process_limit(struct connection *conn,
- unsigned int *limit_r);
+/* Returns the last process_limit returned by a worker connection handshake.
+ If no handshakes have been received yet, returns 0. */
+unsigned int worker_connections_get_process_limit(void);
/* Send a new indexing request for username+mailbox. The status callback is
called as necessary with the given context. Requests can be queued, but
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,
struct connection **conn_r)
{
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)
return FALSE;
if (worker_pool_add_connection(pool, conn_r) < 0)