'Linux read dilemma

I need to read from a fifo. Using ssize_t read(int fd, void *buf, size_t count);, I faced the following situation.

When a large set of data must be read from fifo, I get the Returned (i.e. ssize_t) -1, and errno == 11, meaning "device is busy".

After writing the code to handle that, I tried something which sends a small amount of data to fifo. In this case, after the first read I still get Returned == -1 and errno == 11. Well, somehow the OS must differentiate between "no data available", and "device being busy". Either set Returned to 0, or change errno.

The only other thing to do is to see if read() returned fewer than count. But what will happen if the last read was so that " Returned == count"? That will result in an infinite loop of checking for errno 11, and trying again.

Is there a better solution to this?

The language used is C++.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source