mirror of
https://github.com/paxed/dgamelaunch.git
synced 2025-09-26 03:08:50 +02:00
Use one select() call to both delay and detect keypresses.
git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@333 db0b04b0-f4d1-0310-9a6d-de3e77497b0e
This commit is contained in:
parent
30973454e4
commit
ca91ccc027
15
ttyplay.c
15
ttyplay.c
@ -139,19 +139,14 @@ ttypread (FILE * fp, Header * h, char **buf, int pread)
|
|||||||
{
|
{
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
fd_set readfs;
|
fd_set readfs;
|
||||||
struct timeval zerotime;
|
struct timeval w = { 0, 100000 };
|
||||||
|
|
||||||
zerotime.tv_sec = 0;
|
|
||||||
zerotime.tv_usec = 0;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read persistently just like tail -f.
|
* Read persistently just like tail -f.
|
||||||
*/
|
*/
|
||||||
while (ttyread (fp, h, buf, 1) == READ_EOF)
|
while (ttyread (fp, h, buf, 1) == READ_EOF)
|
||||||
{
|
{
|
||||||
struct timeval w = { 0, 100000 };
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
select (0, NULL, NULL, NULL, &w);
|
|
||||||
clearerr (fp);
|
clearerr (fp);
|
||||||
if (counter++ > (20 * 60 * 10))
|
if (counter++ > (20 * 60 * 10))
|
||||||
{
|
{
|
||||||
@ -159,13 +154,11 @@ ttypread (FILE * fp, Header * h, char **buf, int pread)
|
|||||||
printf ("Exiting due to 20 minutes of inactivity.\n");
|
printf ("Exiting due to 20 minutes of inactivity.\n");
|
||||||
exit (-23);
|
exit (-23);
|
||||||
}
|
}
|
||||||
|
FD_ZERO (&readfs);
|
||||||
|
|
||||||
/* look for keypresses here. as good a place as any */
|
|
||||||
FD_SET (STDIN_FILENO, &readfs);
|
FD_SET (STDIN_FILENO, &readfs);
|
||||||
select (1, &readfs, NULL, NULL, &zerotime);
|
select (1, &readfs, NULL, NULL, &w);
|
||||||
if (FD_ISSET (0, &readfs))
|
if (FD_ISSET (0, &readfs))
|
||||||
{ /* a user hits a character? */
|
{ /* user hits a character? */
|
||||||
char c;
|
char c;
|
||||||
read (STDIN_FILENO, &c, 1); /* drain the character */
|
read (STDIN_FILENO, &c, 1); /* drain the character */
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user