while (!$die) {
foreach my $key ($select->can_read()) { # foreach
if ($key eq $server) { # if $bay eq $server
next if $key eq "";
my $bay = $server->accept or next;
my $ip = $bay->peerhost();
my $ident = _uid();
$lkup{$ident} = $bay;
$pm->start($ident) and next; # <-- spawn worker here
$select->add($bay);
my $buffer = <$bay>;
if ($buffer =~ m/^GET\s\/\sHTTP\/1\.1/) {
print "OK";
sendHeader($bay);
my $html=<<"EOT";
<html>
<head>
</head>
<body style='background-color: blue'>
</body>
</html>
EOT
$bay->syswrite($html);
}
print "$buffer\n";
$pm->finish(0, { ip => $ip });
}
}
$pm->wait_all_children;
}
Regards, Mario
|