One should not attempt to mix buffered I/O (like "read" or <FH>) with "select"

Most definitely. Data could be waiting in the buffer and select wouldn't know anything about it.

while (sysread(FIFO, $l, 255)) { $fifodata .= $l; }

Using while there defies the purpose of using select. If there's less than 256 bytes available, sysread will block the second time through the loop. You want:

my $rv = sysread(FIFO, $fifodata, 64*1024, length($fifodata));

(Big is good. It's not a problem if fewer bytes are available.)

The "ready for reading" half of your select loop should look something like:

my $rv = sysread(FIFO, $fifodata, 64*1024, length($fifodata)); if (!defined($rv)) { ... handle error ... } if (!$rv) { ... handle eof. There might be a partial message in $fifodata ... } while (...$fifodata contains a complete message...) { ...extract message from $fifodata... ...process message... }

For fixed length records, the bottom loop might look like

while (length($fifodata) > $MSG_SIZE) { my $msg = substr($fifodata, 0, $MSG_SIZE, ''); process_msg($msg); }

For variable length records, s/// is convenient

while ($fifodata =~ s/^([^\n]*\n)//) { my $msg = $1; process_msg($msg); }

In reply to Re: Malfunctioning select() call on a FIFO by ikegami
in thread Malfunctioning select() call on a FIFO by Llew_Llaw_Gyffes

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.