Home > Archive > PERL Miscellaneous > January 2006 > IO::Select->can_read returns immediately
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
IO::Select->can_read returns immediately
|
|
| Brian T Glenn 2006-01-27, 6:59 pm |
| I am attempting to use IO::Select to poll a FIFO created by mkfifo. The
FIFO has absolutely no writers attached to it. The following is the
code:
$fifo = IO::File->new();
fatal("Could not open FIFO for reading: $!") unless $fifo->open($cfg{'General'}{'FIFO'});
# Prepare to enter the main loop
$loop = IO::Select->new($fifo);
do_log(1,"Entering processing loop\n");
while(1) {
@tasklist = $loop->can_read();
foreach my $fh (@tasklist) {
if ($fh == $fifo) {
do_log(5,"Received a message from the FIFO");
}
else {
do_log(5,"Receiving a message from another source");
}
}
}
__END__
Shouldn't the can_read() method block until data appears on the FIFO? I
have tried it both with and without a timeout, and the process spins
indefinitely, filling the syslog with "Received a message from the FIFO".
I never receive the message "Receiving a message from another source" in
the syslog. There are also no other filehandles attached to the
IO::Select object.
Thanks in advance,
--
Brian T Glenn
delink.net Internet Services
| |
| xhoster@gmail.com 2006-01-27, 6:59 pm |
| Brian T Glenn <glenn-nntp@this.delink.is.net.invalid> wrote:
> I am attempting to use IO::Select to poll a FIFO created by mkfifo. The
> FIFO has absolutely no writers attached to it. The following is the
> code:
Your code is not runnable. If I make my best guesses in order to make it
runnable, it does not display the symptoms you report.
> $fifo = IO::File->new();
> fatal("Could not open FIFO for reading: $!") unless
> $fifo->open($cfg{'General'}{'FIFO'});
What is in $cfg{'General'}{'FIFO'} ?
In my hands, the opening of a fifo with absolutely no writers attached
blocks forever. Not the read, but the open itself.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
| |
| Jim Gibson 2006-01-27, 6:59 pm |
| In article <slrndtkfhp.asg.glenn-nntp@ziegchen.delink.net>, Brian T
Glenn <glenn-nntp@this.delink.is.net.invalid> wrote:
> I am attempting to use IO::Select to poll a FIFO created by mkfifo. The
> FIFO has absolutely no writers attached to it. The following is the
> code:
>
> $fifo = IO::File->new();
> fatal("Could not open FIFO for reading: $!") unless
> $fifo->open($cfg{'General'}{'FIFO'});
>
> # Prepare to enter the main loop
> $loop = IO::Select->new($fifo);
> do_log(1,"Entering processing loop\n");
> while(1) {
> @tasklist = $loop->can_read();
> foreach my $fh (@tasklist) {
> if ($fh == $fifo) {
> do_log(5,"Received a message from the FIFO");
> }
> else {
> do_log(5,"Receiving a message from another source");
> }
> }
> }
>
> __END__
>
> Shouldn't the can_read() method block until data appears on the FIFO? I
> have tried it both with and without a timeout, and the process spins
> indefinitely, filling the syslog with "Received a message from the FIFO".
Yes, since can_read is not blocking, there must be data ready to read
on the FIFO. If you don't actually read the data from the FIFO, then it
will still be ready the next time you call can_read. Try reading the
data:
print <$fh>;
>
> I never receive the message "Receiving a message from another source" in
> the syslog. There are also no other filehandles attached to the
> IO::Select object.
can_read will either return an empty list or a list with $fifo as its
only element. There is no way you can ever print "Receiving a message
from another source".
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
| |
| attn.steven.kuo@gmail.com 2006-01-27, 6:59 pm |
| Brian T Glenn wrote:
> I am attempting to use IO::Select to poll a FIFO created by mkfifo. The
> FIFO has absolutely no writers attached to it. The following is the
> code:
>
> $fifo = IO::File->new();
> fatal("Could not open FIFO for reading: $!") unless $fifo->open($cfg{'General'}{'FIFO'});
What happens if you open the $fifo for both
read and write? E.g.,
$fifo->open('/my/fifo/here', O_RDWR).
> # Prepare to enter the main loop
> $loop = IO::Select->new($fifo);
> do_log(1,"Entering processing loop\n");
> while(1) {
> @tasklist = $loop->can_read();
> foreach my $fh (@tasklist) {
> if ($fh == $fifo) {
> do_log(5,"Received a message from the FIFO");
> }
> else {
> do_log(5,"Receiving a message from another source");
> }
> }
> }
>
> __END__
>
> Shouldn't the can_read() method block until data appears on the FIFO? I
> have tried it both with and without a timeout, and the process spins
> indefinitely, filling the syslog with "Received a message from the FIFO".
>
> I never receive the message "Receiving a message from another source" in
> the syslog. There are also no other filehandles attached to the
> IO::Select object.
--
Regards,
Steven
|
|
|
|
|