From 308e4e0126b7841e23a6135f884ba761eaacb58a Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 16 Aug 2011 11:09:20 -0400 Subject: s3-prefork: add a few more utility functions Add a few util functions children side so that daemons do not have to care about properly setting num_clients and state. Let a common helper do it so that they are all consistent. Signed-off-by: Andreas Schneider Signed-off-by: Simo Sorce --- source3/lib/server_prefork_util.c | 23 +++++++++++++++++++++++ source3/lib/server_prefork_util.h | 3 +++ 2 files changed, 26 insertions(+) diff --git a/source3/lib/server_prefork_util.c b/source3/lib/server_prefork_util.c index 6b1e249335..8d7d0d2bb5 100644 --- a/source3/lib/server_prefork_util.c +++ b/source3/lib/server_prefork_util.c @@ -115,3 +115,26 @@ void pfh_manage_pool(struct tevent_context *ev_ctx, DEBUG(10, ("Stats: children: %d, allowed connections: %d\n", total, prefork_count_allowed_connections(pool))); } + +void pfh_client_terminated(struct pf_worker_data *pf) +{ + if (pf->num_clients >= 0) { + pf->num_clients--; + } else { + if (pf->status != PF_WORKER_EXITING) { + DEBUG(1, ("Invalid num clients, stopping!\n")); + } + pf->status = PF_WORKER_EXITING; + pf->num_clients = -1; + } +} + +bool pfh_child_allowed_to_accept(struct pf_worker_data *pf) +{ + if (pf->status == PF_WORKER_EXITING || + pf->status == PF_WORKER_ACCEPTING) { + return false; + } + + return (pf->num_clients < pf->allowed_clients); +} diff --git a/source3/lib/server_prefork_util.h b/source3/lib/server_prefork_util.h index 5715f06f4a..65e85dd350 100644 --- a/source3/lib/server_prefork_util.h +++ b/source3/lib/server_prefork_util.h @@ -46,4 +46,7 @@ void pfh_manage_pool(struct tevent_context *ev_ctx, struct pf_daemon_config *cfg, struct prefork_pool *pool); +void pfh_client_terminated(struct pf_worker_data *pf); +bool pfh_child_allowed_to_accept(struct pf_worker_data *pf); + #endif /* _SERVER_PREFORK_UTIL_H_ */ -- cgit