Guten Abend.
Also langsam bekomme ich echt die Krise.
Jetzt habe ich es mit Parallel::ForkManager versucht und jetzt können schon wieder keine Globs gespeichert werden.
Geht das überhaupt nicht oder gibt es eine andere Möglichkeit ?
Hier ein Codebeispiel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/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)=@_;
# Jetzt Sockets updaten :-)
my $sock = $get->{socket};
my $ip = $get->{ip};
my $id = $get->{ident};
$clients{$sock}->{socket} = $sock;
$clients{$sock}->{ip} = $ip;
$clients{$sock}->{ident} = $ident;
# Ende Update
});
$server->autoflush(1); # Autoflush für ältere Perl Versionen.
$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;
my @phrase = ("a" .."z","A".."Z",0..9);
my $ident = join '', map { $phrase[int rand @phrase] } 1..10;
$clients{$bay}->{ip} = $ip;
$clients{$bay}->{ident} = $ident;
foreach my $client( keys %clients ){
print "Verbindung von $clients{$client}->{ip} mit der Ident $clients{$client}->{ident}... OK\n";
}
my $data = $pm->finish(0, { ip => $ip, ident => $ident, socket => \*{ $bay } });
}
}
$pm->wait_all_children;
}
Jetzt kommt folgende Fehlermeldung:
The storable module was unable to store the child's data structure to the temp file "/tmp/jtXd3_MxiB/Parallel-ForkManager-8516-8518.txt": Can't store GLOB items at /usr/lib/i386-linux-gnu/perl/5.24/Storable.pm line 265, at /usr/local/share/perl/5.24.1/Parallel/ForkManager.pm line 84.
Es muss doch eine Möglichkeit geben, einen Verweis auf den Socket vom Kindprozess an den Elternprozess zu senden, das gibts doch wohl gar nicht.
Ich möchte alle Sockets später für $socket->syswrite() parat haben.
Mann mein Kopf qualmt schon *lach*
lg
Last edited: 2017-08-11 20:26:14 +0200 (CEST)