in reply to Re: Malfunctioning select() call on a FIFO
in thread Malfunctioning select() call on a FIFO
The correction on the usage of sysread() is taken. However, I have to point out that this misses the point of the problem. My problem is not how to correctly read from the FIFO; a simple "$fifodata = <FIFO>;" has always worked here (though I'll admit sysread() is probably better). The problem is how to make the select() on the FIFO work properly again instead of always returning true, so that the handler sleeps until there's data available on the FIFO instead of going into a tight loop and repeatedly trying to read from the FIFO as fast as the CPU can execute the inner loop. The only reason I even tried using sysread() instead was in case <FIFO> was somehow leaving something on the FIFO that was making select() think new data had become available to read.
I point out again that this select() call used to work, and has not been changed since then; it's just ... stopped working. The "if (select(...)) {...}" call, on the FIFO, has become effectively an "if (1) {...}" after the first time the other end of the FIFO is written to.
Just to make sure the other end was being properly closed, I wrote this little test tool:
#!/usr/bin/perl my $fifo = shift(@ARGV) || die "No FIFO"; if (-p $fifo) { open(FIFO, ">$fifo") || die "Cannot open $fifo for writing"; print FIFO "/.\n" || die "Cannot write to $fifo"; close(FIFO) || die "Could not close $fifo"; } else { print "$p is not a FIFO.\n"; }
I start the client, it runs normally with negligible CPU utilization; I run the test script; it opens the FIFO, writes to it, closes the FIFO, and exits; the client executes the command sent through the FIFO; and client CPU utilization goes immediately to 100% and stays there, because every select() call on the FIFO after the first command is read from it is saying that there is data on the FIFO to read, even after the writeable end of the FIFO has been closed.
Thinking about it, it's been long enough since I last used this functionality of the client that it's entirely possible that it stopped working when I upgraded from Perl-5.8 to Perl-5.10, or possibly even when I upgraded from Perl-5.6 to Perl-5.8.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Malfunctioning select() call on a FIFO
by ikegami (Patriarch) on Jan 06, 2010 at 19:30 UTC | |
by Llew_Llaw_Gyffes (Scribe) on Jan 06, 2010 at 20:46 UTC | |
by ikegami (Patriarch) on Jan 06, 2010 at 21:46 UTC | |
by Llew_Llaw_Gyffes (Scribe) on Jan 06, 2010 at 21:52 UTC |