HTTP::Daemon
. 当我停止并启动脚本时,似乎仍在监听端口,并收到一条错误消息,指出我的HTTP::Daemon实例未定义。如果我尝试在脚本停止一分钟后启动它,它工作正常,可以再次绑定到端口。
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);
}
编辑:
$d->close()
但在尝试重新启动脚本时仍会出现相同的错误。
END { $d->close(); }
$SIG{'INT'} = 'CLEANUP';
$SIG{__WARN__} = 'CLEANUP';
$SIG{__DIE__} = 'CLEANUP';
sub CLEANUP {
$d->close();
undef($d);
print "\n\nCaught Interrupt (^C), Aborting\n";
exit(1);
}