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.

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; }
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.

After Compline,
Zaxo


In reply to Re: blocking, non-blocking, and semi-blocking by Zaxo
in thread blocking, non-blocking, and semi-blocking by genecutl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.