s3-prefork: add a few more utility functions
authorSimo Sorce <idra@samba.org>
Tue, 16 Aug 2011 15:09:20 +0000 (11:09 -0400)
committerSimo Sorce <idra@samba.org>
Sun, 21 Aug 2011 13:05:05 +0000 (09:05 -0400)
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 <asn@samba.org>
Signed-off-by: Simo Sorce <idra@samba.org>
source3/lib/server_prefork_util.c
source3/lib/server_prefork_util.h

index 6b1e249335f6b14abf2eb3f3038446170a1de46d..8d7d0d2bb556f4d0f069c582e11c0abc7a2c7eea 100644 (file)
@@ -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);
+}
index 5715f06f4aaae98b30fbfc4ce1da139def8f6edf..65e85dd3505791c38ba12328d41f74ba5b3286d3 100644 (file)
@@ -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_ */