mirror of https://github.com/yandex/odyssey.git
odissey: implement client pool iterator
This commit is contained in:
parent
c3c782b854
commit
6d4d735d58
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 +
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue