marlius
asked on
Can select($rout,....) be made to block on EOF
Hi experts,
My intention is to monitor multiple files for new data to read. For this I use select($rout,....) with a timeout of undef, which blocks until at least one file is ready for reading. Unfortunately, select($rout,....) also seems to return when a file has reached EOF. The following code, in which I was expecting select($rout,....) to block until new data is appended to the end of the file, returns immediately (with no data):
#####################
#!/usr/bin/perl -w
use strict;
use IO::File;
use IO::Select;
my $select = IO::Select->new();
my $fh = IO::File->new($ARGV[0], O_RDONLY | O_NONBLOCK);
sysseek($fh, 0, SEEK_END); # See? I'm at end of file
$select->add($fh);
my @ready = $select->can_read(undef);
my $char;
$ready[0]->sysread($char, 1); # non-blocking read
print "The next char is ", $char, "\n";
#####################
My question is, can select($rout,....) be made to block at EOF until new data appears? Or will I have to resort to polling?
My intention is to monitor multiple files for new data to read. For this I use select($rout,....) with a timeout of undef, which blocks until at least one file is ready for reading. Unfortunately, select($rout,....) also seems to return when a file has reached EOF. The following code, in which I was expecting select($rout,....) to block until new data is appended to the end of the file, returns immediately (with no data):
#####################
#!/usr/bin/perl -w
use strict;
use IO::File;
use IO::Select;
my $select = IO::Select->new();
my $fh = IO::File->new($ARGV[0], O_RDONLY | O_NONBLOCK);
sysseek($fh, 0, SEEK_END); # See? I'm at end of file
$select->add($fh);
my @ready = $select->can_read(undef);
my $char;
$ready[0]->sysread($char, 1); # non-blocking read
print "The next char is ", $char, "\n";
#####################
My question is, can select($rout,....) be made to block at EOF until new data appears? Or will I have to resort to polling?
select is supposed to do that IMO. So you might have to use other methods.
ASKER
Hi inq123,
Thanks for your comment. For now, I've decided to forget about select($rout,....) and go with polling. However I am still interested in any comments other experts might want to add, so I won't be closing this question just yet.
Thanks for your comment. For now, I've decided to forget about select($rout,....) and go with polling. However I am still interested in any comments other experts might want to add, so I won't be closing this question just yet.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi inq123 and jmcg,
Thank you both for your comments.
Thank you both for your comments.