I meet you halfway with a patch that seems perfectly correct but has not been carefully tested. :-)
I named the callback register_child, in reference to delete_child, but had also considered fork_hook.
--
rjbs
From 47a7d077847ef993ad609147b39a46250cab40c2 Mon Sep 17 00:00:00 2001
From: Ricardo Signes <rjbs@cpan.org>
Date: Thu, 28 Jan 2016 18:56:12 -0500
Subject: [PATCH] add register_child, the inverse of delete_child
---
lib/Net/Server.pm | 2 ++
lib/Net/Server/Fork.pm | 2 ++
lib/Net/Server/PreFork.pm | 1 +
lib/Net/Server/PreForkSimple.pm | 1 +
4 files changed, 6 insertions(+)
diff --git a/lib/Net/Server.pm b/lib/Net/Server.pm
index 59fb44e..3be6eb2 100644
--- a/lib/Net/Server.pm
+++ b/lib/Net/Server.pm
@@ -671,6 +671,7 @@ sub done {
}
sub pre_fork_hook {}
+sub register_child {}
sub child_init_hook {}
sub child_finish_hook {}
@@ -691,6 +692,7 @@ sub run_dequeue { # fork off a child process to handle dequeuing
exit;
}
$self->log(4, "Running dequeue child $pid");
+ $self->register_child($pid);
$self->{'server'}->{'children'}->{$pid}->{'status'} = 'dequeue'
if $self->{'server'}->{'children'};
diff --git a/lib/Net/Server/Fork.pm b/lib/Net/Server/Fork.pm
index 668d400..fbb1b36 100644
--- a/lib/Net/Server/Fork.pm
+++ b/lib/Net/Server/Fork.pm
@@ -145,6 +145,8 @@ sub loop {
exit;
}
+ $self->register_child($pid);
+
# parent
close($prop->{'client'}) if !$prop->{'udp_true'};
$prop->{'children'}->{$pid}->{'status'} = 'processing';
diff --git a/lib/Net/Server/PreFork.pm b/lib/Net/Server/PreFork.pm
index d986f1a..e24276c 100644
--- a/lib/Net/Server/PreFork.pm
+++ b/lib/Net/Server/PreFork.pm
@@ -177,6 +177,7 @@ sub run_n_children {
$prop->{'children'}->{$pid}->{'sock'} = $parentsock;
}
+ $self->register_child($pid);
$prop->{'children'}->{$pid}->{'status'} = 'waiting';
$prop->{'tally'}->{'waiting'} ++;
diff --git a/lib/Net/Server/PreForkSimple.pm b/lib/Net/Server/PreForkSimple.pm
index fcccb74..082b54e 100644
--- a/lib/Net/Server/PreForkSimple.pm
+++ b/lib/Net/Server/PreForkSimple.pm
@@ -145,6 +145,7 @@ sub run_n_children {
$self->fatal("Bad fork [$!]") if ! defined $pid;
if ($pid) {
+ $self->register_child($pid);
$prop->{'children'}->{$pid}->{'status'} = 'processing';
} else {
$self->run_child;
--
2.6.2