【发布时间】:2009-10-07 20:03:17
【问题描述】:
下面是一个 Perl 脚本,其唯一目的是接收一个 HTTP 请求,并吐出“503 Service Unavailable”和一条短消息。它工作正常,除了在许多情况下,连接重置,这会导致浏览器显示错误消息。这是在 Win32 上。我不知道它有什么问题。
#!/usr/local/bin/perl
use strict;
use IO::Socket::INET;
my $f = join('', <DATA>);
$SIG{CHLD} = 'IGNORE';
my $sock = IO::Socket::INET->new(ReuseAddr => 1, Listen => 512, LocalPort => 80, LocalHost => '0.0.0.0', Proto => 'tcp');
die "Cant't create a listening socket: $@" unless $sock;
while (my $connection = $sock->accept) {
my $child;
die "Can't fork: $!" unless defined ($child = fork());
if ($child == 0) {
#print "Child $$ running. ";
$sock->close;
do_it($connection);
#print "Child $$ exiting.\n";
exit 0;
} else {
print "Connection from ".$connection->peerhost."\n";
$connection->close();
}
}
sub do_it {
my $socket = shift;
my $pr = print $socket $f;
if (!$pr) {
$socket->close();
exit(0);
}
}
__DATA__
HTTP/1.1 503 Service Unavailable
Date: Mon, 12 Mar 2009 19:12:16 GMT
Server: Down
Connection: close
Content-Type: text/html
<html>
<head><title>Down for Maintenance</title></head>
<body>
<h2>Down for Maintenance</h2>
<p>The site is down for maintenance. It will be online again shortly.</p>
</body>
</html>
【问题讨论】:
-
您要在哪个版本的 Windows 上试用?有多少个同时连接?
-
当只有我在本地机器上时会发生这种情况,并且我用鼠标快速刷新(这不是那么快......)。操作系统 = XP。