Actually, it turns out that didn't work. The file tail pipe would stop working with `ps` showing "tail [defunct]". I tried closing that pipe and then opening a new one when the sysread returned undef, but the new pipe wouldn't give me any output. I found another file tailing trick in the Perl Cookbook which now verifiably works for me. Here is the code:
use IO::Select; use IO::Socket; use POSIX; ##### setup the file.... # open it open my $tail, $FILE or die $!; # set to non-blocking fcntl( $tail, F_SETFL(), O_NONBLOCK() ); # [ fill up the file info buffer ] ###### setup the socket.... + $main_sock; $readable_handles; $main_sock = new IO::Socket::INET( LocalHost => 'localhost', LocalPort => $PORT, Listen => 8, Proto => 'tcp', ReuseAddr => 1, ); $readable_handles = new IO::Select(); $readable_handles->add($main_sock); while (1) { ######### do file tail stuff here... + # unset the EOF (as seen in Perl Cookbook) $tail->clearerr(); # read any new lines if ( @lines = (<$tail>) ) { # [ add @lines to buffer ] # [ discard old lines from buffer ] # [ other processing of data... ] } ######### do TCP socket stuff.... + ($new_readable) = IO::Select->select( $readable_handles, undef, un +def, $TIMEOUT ); foreach my $sock (@$new_readable) { if ( $sock == $main_sock ) { $new_sock = $sock->accept(); $new_sock->autoflush(1); $readable_handles->add($new_sock); } else { if ( $ret = sysread $sock, $buf, 4 ) { # [ process the received info, generate $reply ] # reply to the client + print $sock $reply; } # close the client + $readable_handles->remove($sock); close $sock; } } }

In reply to Re^3: blocking, non-blocking, and semi-blocking by genecutl
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.