c++ - check whether fgets would block -
i wondering whether in c possible peek in input buffer or perform similar trickery know whether call fgets block @ later time. java allows calling bufferedreader.ready(), way can implement console input this:
while (on && in.ready()) { line = in.readline(); /* line */ if (!in.ready()) thread.sleep(100); }
this allows external thread gracefully shutdown input loop setting on false; i'd perform similar implementation in c without resorting non portable tricks, know can make "timed out fgets" under unix resorting signals or (better, though requering take care of buffering) reimplement on top of recv/select, i'd prefer work on windows too.
tia
suggest go socket i/o routines,preferably poll() required millisecond timeout , can interpret timeout ( return value = -1 ) unavailability of data in input buffer.
in opinion,there no non-blocking standard i/o function achieve functionality.
Comments
Post a Comment