J
Josh Denny
I am trying to write a simple file transfer server in perl that will
reside of both windows and linux platforms. Basically, it accepts a
connection, forks a process, and then should close the child. on
windows, it dies after "accumulating" 64 children opened - however,
they should all (or most) have exited by that time. Any idea how to
get my children to exit and free up space for more connections?
Thanks - Josh
here's the relevant part of my code:
sub reaper { #to eliminate dead child processess
$waitpid=wait;
$SIG{CHLD}=\&reaper;
}
$SIG{CHLD}=\&reaper;
main();
sub main {
my $contentlength;
print "Loading data transfer server on port
$datatransfer_port...\n\n";
socket_listen (\*SERVER, $datatransfer_port);
while (accept ($client, SERVER)) {
my ($c_port, $c_iaddr) = sockaddr_in(getpeername($client));
my(@inetaddr) = unpack('C4', $c_iaddr);
my $from = join('.', @inetaddr);
if (my $pid = fork) { #if it is the server, then next
close $client or die "Client socket close failed: $!";
} elsif (defined $pid) { #a child
client_connect($client, $from); #processes the clients connection
exit(0);
} else {
die "fork error: $!"; #program dies here after 64
client_connect's
}
}
}
reside of both windows and linux platforms. Basically, it accepts a
connection, forks a process, and then should close the child. on
windows, it dies after "accumulating" 64 children opened - however,
they should all (or most) have exited by that time. Any idea how to
get my children to exit and free up space for more connections?
Thanks - Josh
here's the relevant part of my code:
sub reaper { #to eliminate dead child processess
$waitpid=wait;
$SIG{CHLD}=\&reaper;
}
$SIG{CHLD}=\&reaper;
main();
sub main {
my $contentlength;
print "Loading data transfer server on port
$datatransfer_port...\n\n";
socket_listen (\*SERVER, $datatransfer_port);
while (accept ($client, SERVER)) {
my ($c_port, $c_iaddr) = sockaddr_in(getpeername($client));
my(@inetaddr) = unpack('C4', $c_iaddr);
my $from = join('.', @inetaddr);
if (my $pid = fork) { #if it is the server, then next
close $client or die "Client socket close failed: $!";
} elsif (defined $pid) { #a child
client_connect($client, $from); #processes the clients connection
exit(0);
} else {
die "fork error: $!"; #program dies here after 64
client_connect's
}
}
}