On Mon, Apr 18, 2005 at 03:22:11PM +1200, Jon Keller wrote:
> I'm trying to build a ssl web server that will allow mutiple
> connections at once. I'm using HTTP::Daemon::SSL, my code is pasted
> below. The forking seems to be working however if I telnet to the
> port the daemon is running on, then send lots of request to the
> daemon via a web browser, after about 10 reloads the browser stops
> getting responses from the serer. Once I close the other connection
> to the daemon, the browser gets the response its suppose to. The
> $rand is just to show that the response is different from the last
> one.
> The same thing seems to happen to a non ssl daemon.
Jon,
So it is not a HTTP::Daemon::SSL problem, but a HTTP::Daemon problem?
> Could someone point me in the right direction for making an ssl
> daemon that supports multiple connections?
I am not sure about your process/children handling, but in your code I
do not see any reaping of children. Isn't it the case that a parent
has to do something like this (see Perl Cookbook somewhere):
use POSIX qw(WNOHANG);
sub REAPER {
1 until (-1 == waitpid(-1, WNOHANG));
}
$SIG{CHLD} = \&REAPER;
Otherwise you end up with a lot of zombie processes, I guess.
> while (my ($c) = $d->accept) {
> my $pid = fork();
> if ($pid == 0) {
> while (my $r = $c->get_request) {
> my $rand = rand(100);
> print "Got Request $rand " . $r->method . "\n";
> my $res = HTTP::Response->new(200);
> $res->content("Hello there $rand");
> $c->send_response($res);
> }
> $c->close;
> undef($c);
> exit(0);
> }
> }
Not sure whether the $c->close AND the undef($c) is necessary, but if
the parent AND the child have a copy of $c, isn't it the case that the
kernel now has 2 links and should the parent not get rid of its link
to keep a clean house? Something like
if (i am the parent) {
$c->close;
} else { # I am the child
# do something
$c->close;
exit 0;
}
\rho