diff --git a/sources/client_pool.c b/sources/client_pool.c index 7130f020..af1a3e25 100644 --- a/sources/client_pool.c +++ b/sources/client_pool.c @@ -113,3 +113,37 @@ od_clientpool_next(od_clientpool_t *pool, od_clientstate_t state) client = od_container_of(target->next, od_client_t, link_pool); return client; } + +od_client_t* +od_clientpool_foreach(od_clientpool_t *pool, + od_clientstate_t state, + od_clientpool_cb_t callback, + void *arg) +{ + od_list_t *target = NULL; + switch (state) { + case OD_CACTIVE: + target = &pool->active; + break; + case OD_CQUEUE: + target = &pool->queue; + break; + case OD_CPENDING: + target = &pool->pending; + break; + case OD_CUNDEF: + assert(0); + break; + } + od_client_t *client; + od_list_t *i, *n; + od_list_foreach_safe(target, i, n) { + client = od_container_of(i, od_client_t, link_pool); + int rc; + rc = callback(client, arg); + if (rc) { + return client; + } + } + return NULL; +} diff --git a/sources/client_pool.h b/sources/client_pool.h index 1dd679dc..9d11a1d3 100644 --- a/sources/client_pool.h +++ b/sources/client_pool.h @@ -9,6 +9,8 @@ typedef struct od_clientpool od_clientpool_t; +typedef int (*od_clientpool_cb_t)(od_client_t*, void*); + struct od_clientpool { od_list_t active; @@ -25,6 +27,12 @@ void od_clientpool_set(od_clientpool_t*, od_client_t*, od_client_t* od_clientpool_next(od_clientpool_t*, od_clientstate_t); +od_client_t* +od_clientpool_foreach(od_clientpool_t*, + od_clientstate_t, + od_clientpool_cb_t, + void*); + static inline int od_clientpool_total(od_clientpool_t *pool) { return pool->count_active + pool->count_queue + diff --git a/sources/route_pool.c b/sources/route_pool.c index bba18450..7472a508 100644 --- a/sources/route_pool.c +++ b/sources/route_pool.c @@ -134,9 +134,9 @@ od_routepool_next(od_routepool_t *pool, od_serverstate_t state) } od_server_t* -od_routepool_foreach(od_routepool_t *pool, od_serverstate_t state, - od_serverpool_cb_t callback, - void *arg) +od_routepool_server_foreach(od_routepool_t *pool, od_serverstate_t state, + od_serverpool_cb_t callback, + void *arg) { od_route_t *route; od_list_t *i, *n; @@ -151,6 +151,24 @@ od_routepool_foreach(od_routepool_t *pool, od_serverstate_t state, return NULL; } +od_client_t* +od_routepool_client_foreach(od_routepool_t *pool, od_clientstate_t state, + od_clientpool_cb_t callback, + void *arg) +{ + od_route_t *route; + od_list_t *i, *n; + od_list_foreach_safe(&pool->list, i, n) { + route = od_container_of(i, od_route_t, link); + od_client_t *client; + client = od_clientpool_foreach(&route->client_pool, state, + callback, arg); + if (client) + return client; + } + return NULL; +} + static inline int od_routepool_stats_mark(od_routepool_t *pool, char *database, diff --git a/sources/route_pool.h b/sources/route_pool.h index a91a2492..87ee6735 100644 --- a/sources/route_pool.h +++ b/sources/route_pool.h @@ -36,8 +36,12 @@ od_server_t* od_routepool_next(od_routepool_t*, od_serverstate_t); od_server_t* -od_routepool_foreach(od_routepool_t*, od_serverstate_t, - od_serverpool_cb_t, void*); +od_routepool_server_foreach(od_routepool_t*, od_serverstate_t, + od_serverpool_cb_t, void*); + +od_client_t* +od_routepool_client_foreach(od_routepool_t*, od_clientstate_t, + od_clientpool_cb_t, void*); int od_routepool_stats(od_routepool_t *pool, od_routepool_stats_function_t,