Glib::IO->add_watch - file descriptor got locked till the end of all incoming data



I want to update a treeview and this is the reason why i'm using the add_watch function. The child is sending data all the time for many reasons and the problem that i have is the file handler which have the incoming data from child to parent. With watcher each time the child sent data the $line = <$reader> must save this data in $line and call the function.
 But dont know why  the <$reader> just get locked till the end of all $writer>write()  and then it save all those data into $line, and i dont want that, i want to save the data of ->write in $line each time child send data.

Any idea?

 my ($reader, $writer);
    $reader = FileHandle->new;
    $writer = FileHandle->new;

    socketpair($reader, $writer, AF_UNIX, SOCK_STREAM, PF_UNSPEC) or die "socketpair: $!";
    my $pid = fork();
    $reader->autoflush(1);
    $writer->autoflush(1);
    if ($pid){
        # PARENT
        shutdown($writer, 0);
        print "Pare!\n";
        my $line;
        $watcher{$pid} = Glib::IO->add_watch($reader->fileno(), ['in', 'hup'], sub {
                my ($fileno, $condition) = @_;

                print "->cond = $condition\n";
                if ($condition & 'in') {
                    print "->reading from parent!!!\n";
                    $line = <$reader>;
                    print "--->line = $line!\n";
                    my @data="">                    &update_treeview(@data);
                }
                if (($condition & 'hup') and (! defined($line) or $line eq '')) {
                    return FALSE;  # uninstall
                }
                else {";
                    my $line = <$reader>;
                    print "\n---line= $line\n";
                    my @data="">                     &update_treeview(@data);
                }
                return TRUE;  # continue without uninstalling
           });
    }
else {
   ...
   child sent info to parent through $writer->write(data)
 and then $writher->flush;

}


Thanks,


David


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]