How to stop listening on an HTTP::Daemon port in Perl
Posted
by Trevor
on Stack Overflow
See other posts from Stack Overflow
or by Trevor
Published on 2010-06-14T16:48:40Z
Indexed on
2010/06/14
16:52 UTC
Read the original article
Hit count: 223
I have a basic perl HTTP server using HTTP::Daemon. When I stop and start the script, it appears that the port is still being listened on and I get an error message saying that my HTTP::Daemon instance is undefined. If I try to start the script about a minute after it has stopped, it works fine and can bind to the port again.
Is there any way to stop listening on the port when the program terminates instead of having to wait for it to timeout?
use HTTP::Daemon;
use HTTP::Status;
my $d = new HTTP::Daemon(LocalAddr => 'localhost', LocalPort => 8000);
while (my $c = $d->accept) {
while (my $r = $c->get_request) {
$c->send_error(RC_FORBIDDEN)
}
$c->close;
undef($c);
}
© Stack Overflow or respective owner