To check 'regular' std::istream
if there is any pending data I can do just something like this:
bool has_pending_data(std::istream& s) {
return s.peek() >= 0;
}
However, this is different for standard input and named pipes. If I do something like this:
if (has_pending_data(std::cin)) {
// process incoming data
} else {
// do some periodic tasks
}
the else branch is never reached since the execution will block on the peek
function. Is there way to avoid this blocking for standerd input and named pipes?