I'm trying to do non-blocking I/O in straight C so I can get my app to accept input from the console while appearing to perform other tasks at the same time. I've done a small MUD server before, and select() was great for checking for input each loop so my program didn't wait on new data to read. My question is, can I use select() this way for stdin, or is there some other way to do it?
this tends to be operating system dependent. For example, many windows compilers come with a none standard header file <conio.h>, see
http://en.wikipedia.org/wiki/Conio.h
which contains a function kbhit() which returns true if the keyboard has been hit, e.g.
-
while(....) // some loop
-
{
-
if (kbhit())
-
{
-
// keyboard has been hit, read character etc
-
..
-
}
-
.. other processing within the loop
-
}