--- Daemon.pm.orig	Tue Nov 21 12:48:22 2000
+++ Daemon.pm	Tue Nov 21 12:48:20 2000
@@ -33,7 +33,9 @@
 
 package Net::Daemon;
 
-$Net::Daemon::VERSION = '0.32';
+use vars qw{$exit} ;
+
+$Net::Daemon::VERSION = '0.32-1';
 @Net::Daemon::ISA = qw(Net::Daemon::Log);
 
 #
@@ -247,7 +249,10 @@
 	$self->{$var} = $val;
     }
 
-    if (!defined($self->{'mode'})) {
+    if ($self -> {'childs'}) {
+        $self->{'mode'} = 'single';
+    }
+    elsif (!defined($self->{'mode'})) {
 	if (eval { require Thread }) {
 	    $self->{'mode'} = 'threads';
 	} else {
@@ -274,7 +279,7 @@
 	$self->Fatal("Unknown operation mode: $self->{'mode'}");
     }
     $self->{'catchint'} = 1 unless exists($self->{'catchint'});
-    $self->Debug("Server starting in operation mode $self->{'mode'}");
+    $self->Debug("Server starting in operation mode " . ($self -> {'childs'}?"prefork with " . $self -> {'childs'} . " childs":$self->{'mode'}));
 
     $self;
 }
@@ -502,7 +507,7 @@
     my $child_pid;
 
     my $reaper = $self->SigChildHandler(\$child_pid);
-    $SIG{'CHLD'} = $reaper if $reaper;
+    $SIG{'CHLD'} = $reaper if ($reaper && !$self -> {'childs'}) ;
 
     if (!$self->{'socket'}) {
 	$self->{'proto'} ||= ($self->{'localpath'}) ? 'unix' : 'tcp';
@@ -571,6 +576,48 @@
 	$< = ($> = $user);
     }
 
+
+
+   
+    if ($self -> {'childs'}) {
+        my $pid ;        
+
+        my $parent = 1 ;
+
+        for (my $n = 0; $n < $self -> {'childs'}; $n++) {
+	    $pid = fork();
+	    die "Cannot fork: $!" unless defined $pid;
+	    if (!$pid) { #Child
+                $self->{'mode'} = 'single' ;
+                $parent = 0 ;
+                last ;
+            }
+            # Parent
+            $self -> {'childpids'}{$pid} = 1 ;
+        }
+
+        if ($parent) {
+            my $childpid  ;
+            $exit = 0 ;
+            $SIG{'TERM'} = sub { die } ; ;
+            $SIG{'INT'}  = sub { die } ; ;
+            eval {
+                do {
+                    $childpid = wait ;
+                    delete $self -> {'childpids'}{$childpid}  ;
+	            $self->Debug("Child $childpid has exited");
+                }
+                until ($childpid <= 0 || $exit) ;
+            } ;
+            my @pids = keys %{$self -> {'childpids'}} ;
+	    $self->Debug("kill TERM childs:@pids");
+            kill 'TERM', @pids if (@pids)  ; # send a TERM to all childs
+
+            exit (0)  ;
+            }
+    }
+
+
     my $time = $self->{'loop-timeout'} ?
 	(time() + $self->{'loop-timeout'}) : 0;
 
@@ -813,7 +860,7 @@
 =item I<mode> (B<--mode=modename>)
 
 The Net::Daemon server can run in three different modes, depending on
-the environment.
+the environment. (Actually four, see childs parameter below)
 
 If you are running Perl 5.005 and did compile it for threads, then
 the server will create a new thread for each connection. The thread
@@ -830,6 +877,16 @@
 accepted until the Run() method returns. This operation mode is usefull
 if you have neither threads nor fork(), for example on the Macintosh.
 For debugging purposes you can force this mode with "--mode=single".
+
+=item I<childs>
+
+Use this parameter to let Net::Daemon run in prefork mode, which means
+it forks the number of childs processes you give with this parameter,
+and all child handle connections concurrently. The difference to 
+fork mode is, that the child processes continue to run after a 
+connection has terminated and are able to accpect a new connection.
+This is usefull for caching inside the childs process (e.g. 
+DBI::ProxyServer connect_cached attribute)
 
 =item I<options>
 

