azadian has asked for the wisdom of the Perl Monks concerning the following question:
Here's the tiny test program to illustrate the problem:
Here's what I get when I run it:#!/usr/bin/perl # teof2 20201104 NHA # Test eof() for IPC over socketpair filehandle. use diagnostics; use strict 'subs'; use strict 'refs'; use Socket; use IO::Handle; my $child; #filehandle to child process my $parent; #filehandle to parent process my $pid; #Process ID of child process socketpair($child, $parent, AF_UNIX, SOCK_STREAM, PF_UNSPEC) or die "socketpair: $! +"; $child->autoflush(1); $parent->autoflush(1); if ($pid = fork()) { #parent close $parent or die "close: $!\n"; sleep 1; print STDOUT time%1000, ": polling child\n"; if (eof($child)) { print STDOUT time%1000, ": no input from child yet\n"; } else { my $line = <$child>; chomp $line; print STDOUT time%1000, ": received <$line>\n"; } } else { #child die "cannot fork: $!" unless defined $pid; close $child or die "close: $!\n"; print STDOUT time%1000, ": child started\n"; sleep 5; print {$parent} time%1000, ": child printed\n"; close $parent or die "close: $!\n"; exit; }
The only way I can understand this is that eof() is blocking until input appears, and then returning false. Am I missing something here?= ./teof2 325: child started 326: polling child 330: received <330: child printed>
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: eof() blocking
by tybalt89 (Monsignor) on Nov 04, 2020 at 21:05 UTC | |
by azadian (Sexton) on Nov 05, 2020 at 10:07 UTC | |
by tybalt89 (Monsignor) on Nov 05, 2020 at 15:15 UTC | |
by tybalt89 (Monsignor) on Nov 05, 2020 at 15:51 UTC | |
Re: eof() blocking
by choroba (Cardinal) on Nov 04, 2020 at 21:02 UTC | |
by azadian (Sexton) on Nov 05, 2020 at 10:16 UTC |
Back to
Seekers of Perl Wisdom