- 论坛徽章:
- 0
|
修改后 可以了
#!/usr/bin/perl
use strict;
use IO::Socket;
use POSIX 'WNOHANG';
use constant PORT => 2008;
my $quit = 0;
$SIG{CHLD} = sub {while(waitpid(-1,WNOHANG)>0){}};
$SIG{INT} = sub {$quit++};
my $i=1;
my $server_socket = IO::Socket::INET->new
(
LocalPort => PORT,
Listen => SOMAXCONN,
Proto => 'tcp',
Reuse => 1,
Timeout => 60
) or die "ERROR!n";
while(!$quit)
{
next unless my $connection = $server_socket->accept;
defined(my $child = fork()) or die "error!n";
if($child == 0)
{
print "Line ".$i." ";
$server_socket->close;
repeat_server($connection);
exit 0;
}
$connection->close;
$i++;
}
sub repeat_server
{
my $sock = shift;
while(my $line = <$sock>)
{
print $line;
}
} |
|