| vincegata (72) | |
|
Hello, I have a producer application that writes data into a FIFO, and I have a consumer application that reads data from FIFO utilizing select() and read() functions inside of an while(true) loop. After producer is done (it closes and unlinks FIFO) select() on the consumer side keeps endlessly returning "ready" state, and read() returns 0 bytes. I've expected select() to return -1 once the FIFO was closed but it's not the case. How do I catch that FIFO was closed on the producer side? Thank you. P.S. I should post my code but it's a large application, it would take me time to make it into a small prototype. I'd appreciate if someone knows the answer without me having to post the code. | |
|
Last edited on
|
|
| histrungalot (218) | |||||||||
|
You caught it already. In the man page for select:
and man page for read:
So, select is doing what it should and read is as well. The error for select would be:
Also, make sure you call FD_ZERO and FD_SET each time in the loop before you call select. Code modified from http://www.codeforge.com/article/195845 fifoWriter.c - Too lazy to convert to c++
fifoRead.cpp
It is up to you to take action on the read of EOF. Close and remove that fd from the list of file descriptors in the select and continue to process in your loop or not. | |||||||||
|
Last edited on
|
|||||||||
| vincegata (72) | ||
That is the catch - I thought if the file descriptor was closed on the write side, select() on the read side should return EBADF - which is not the case. Thank you for help! | ||
|
Last edited on
|
||