I'm just wondering if it is possible in C to look into the input buffer or perform a similar trick to find out if the fgets call will block later. Java allows you to do something like this by calling BufferedReader.ready (), so I can implement console input of something like this:
while (on && in.ready()) {
line = in.readLine();
if (!in.ready())
Thread.sleep(100);
}
this allows the external thread to gracefully disable the input loop by setting the value to false; I would like to perform a similar implementation in C without resorting to intolerable tricks, I already know that I can do a “fouts timeout” under Unix, resorting to signals or (better, even if requested to take care of buffering) override it on top recv / select, but I would prefer something that works on windows too.
TIA
source
share