Hello.
If have a little Server programmed in IO::Socket and with Module Parallel::ForkManager
#!/usr/bin/perl
use strict;
no strict 'refs';
use warnings;
use IO::Socket;
use IO::Select;
use Parallel::ForkManager;
our $die = 0;
$SIG{INT} = sub{ $die = 1; exit; };
our %clients = ();
our $select = IO::Select->new;
my $server = IO::Socket::INET->new( LocalHost => 'localhost',
LocalPort => 2222,
Proto => 'tcp',
Listen => 10000,
Reuse => 1,
) or die "Sock Error: $!\n";
our $pm = Parallel::ForkManager->new(10);
$pm->run_on_finish(sub{
my($pid,$exitcode,$ident,$exitsignal,$coredump,$get
+)=@_;
my $sock = $get->{socket};
my $ip = $get->{ip};
my $id = $get->{ident};
$clients{$sock}->{socket} = $sock;
$clients{$sock}->{ip} = $ip;
$clients{$sock}->{ident} = $id;
});
$server->autoflush(1);
$select->add($server);
while(!$die){
foreach our $key( $select->can_read()) { # foreach
if($key eq $server) { # if $bay eq $server
next if $key eq "";
our $bay = $server->accept or next;
my $ip = $bay->peerhost();
$select->add($bay);
$pm->start and next;
select($bay);
$|=1;
my @phrase = ("a" .."z","A".."Z",0..9);
my $ident = join '', map { $phrase[int rand @phrase]
+} 1..10;
foreach my $client( keys %clients ){
print "Connection from $clients{$client}->{ip} wit
+h Ident $clients{$client}->{ident} and Socket $clients{$client}->{soc
+ket} ... OK\n";
}
my $data = $pm->finish(0, { ip => $ip, ident => $iden
+t, socket => \*{ $bay } });
}
}
$pm->wait_all_children;
}
sub sendHeader {
my $sock = shift;
my $header =<<"EOT";
HTTP/1.0 200 OK
Content-type: text/html
EOT
$sock->syswrite($header);
}
I want to update the %clients Hash in the kind process.
Later ( in the kind ) i want to write to each socket in %clients like
my $sock = $clients{"WHAT"}->{socket};
$sock->syswrite("hello world");
But now i get an error: Cant store GLOB Items in ForkManager.pm
What i do wrong?