in reply to blocking, non-blocking, and semi-blocking
A handle to a disk file is always ready to read until eof. Writes to the file by other processes after you have opened it will not be seen on your handle. If the writers are trying to obtain exclusive locks on the file, holding your handle open is plain antisocial.
You can watch and tail a file with seek,tell and the -s file test. You haven't shown what you're doing with your socket handles, so I'll skip that, too.
Completely untested. I've altered your while loop to an unconditional one. Your code will quit listening the first time it catches up with traffic.use IO::File; use IO::Socket; use IO::Select; my $file = '/tmp/test_file'; my $sel = IO::Select->new; my $pos = -s $file; my $fh = IO::File->new; # read the file a first time if you like . . . # Add IO::Socket objects to $sel if ($pos < -s $file) { $fh->open($file, 'r') or die $!; $fh->seek($pos, 0); $sel->add($fh); } { my @ready = $sel->can_read; for (@ready) { if ($_ eq $fh) { print <$fh>; $sel->remove($fh); $pos = $fh->tell; $fh->close(); } else { # do socket things } } if ($pos < -s $file) { $fh->open($file, 'r') or die $!; $fh->seek($pos, 0); $sel->add($fh); } last if end_condition(); # for some end condition redo; }
After Compline,
Zaxo
|
|---|