XP is just a number | |
PerlMonks |
Malfunctioning select() call on a FIFOby Llew_Llaw_Gyffes (Scribe) |
on Jan 06, 2010 at 17:22 UTC ( [id://815950]=perlquestion: print w/replies, xml ) | Need Help?? |
Llew_Llaw_Gyffes has asked for the wisdom of the Perl Monks concerning the following question: Brethren, I have a mystery to present today. I have a threaded Perl ICB client. (If you don't know what ICB is, don't worry about it, that's not important to the question.) It was written as a multithreaded application for several reasons, not the least of them being to learn how to use Perl threads. One of its six total threads creates a FIFO, then listens on it for external input piped into the client and passes anything it receives to the input thread, in order to allow external files or program output to be piped into the program as though typed or pasted in directly. The handler for that FIFO is the following function:
The last time I used the external input FIFO functinality, which was quite some time ago, it worked perfectly. I had cause to use it again this morning, and found that it has begun malfunctioning. As soon as anything is written to the FIFO, the FIFO input is processed as it should be, but then CPU utilization goes to 100% and stays there. The debug asserts that I inserted into the code show that after the initial handling of the input, the function goes into a tight loop repeatedly reading nothing from the FIFO:
It appears that once the FIFO has been written to, the select() ALWAYS says there is unread data waiting on the FIFO, yet nothing can be actually read from it. During the tight loop, an eof(FIFO) call inserted at the beginning of the innermost loop always returns true. There is no data on the FIFO to read; but the select() call thinks there is. I see that 'perldoc perlfunc' says: Note: on some Unixes, the select(2) system call may report a socket file descriptor as "ready for reading", when actually no data is available, thus a subsequent read blocks. It can be avoided using always the O_NONBLOCK flag on the socket. See select(2) and fcntl(2) for further details. However, I am already using O_NONBLOCK. It also says: WARNING: One should not attempt to mix buffered I/O (like "read" or <FH>) with "select", except as permitted by POSIX, and even then only on POSIX systems. You have to use "sysread" instead. But I have tried replacing the line:
with the following construct:
I have also tried replacing:
with:
or even:
The behavior remains unchanged, though. No matter what I do, the select() continues to ALWAYS immediately show the FIFO as having data pending after it has been written to once. Can anyone enlighten me as to why this should be, and what I can do to fix it?
Back to
Seekers of Perl Wisdom
|
|