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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |