1
2
3
4
5
6
7
8
9
10
11
12
my $pid = fork();
if (not defined $pid) {
print "resources not avilable.\n";
}
elsif ($pid == 0) {
while(1){
&receive;
}
}
else {
MainLoop;
}
1
2
3
4
5
6
while($select->can_read(10)){
my $msg_in;
#Textempfang
$socket->recv($msg_in, $MAXLENGTH);
unpackReceived($msg_in);
}
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
#!/usr/bin/perl use strict; use warnings; use fork_bufferd_read; my $count=0; my $fbr=fork_bufferd_read->new(sub{ my $buf=shift; $count++; select(undef,undef,undef,0.5); $$buf.="$count\t"; return 0 if($count>35); return 1; }); die ("NO FORK!\n") unless($fbr); for(0..10) { sleep 3; print "READ $_ :".$fbr->read()."\n"; unless($fbr->running()) { print "CHILD EXIT!\n"; last; } }