mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-22 20:21:26 +00:00
posix: sdl: Stop reading STDIN on EOF
If EOF is read on stdin (such as when it is /dev/null), stop calling select() on it. Otherwise, the code goes into an infinite loop attempting to read from stdin which is always ready but never has any data and it never calls the timer callback to progress.
This commit is contained in:
parent
9c765a70bf
commit
d2ac72129d
1 changed files with 18 additions and 6 deletions
|
@ -257,6 +257,7 @@ bool FTTYStartupScreen::NetLoop(bool (*timer_callback)(void *), void *userdata)
|
|||
struct timeval tv;
|
||||
int retval;
|
||||
char k;
|
||||
bool stdin_eof = false;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
|
@ -265,7 +266,10 @@ bool FTTYStartupScreen::NetLoop(bool (*timer_callback)(void *), void *userdata)
|
|||
tv.tv_usec = 500000;
|
||||
|
||||
FD_ZERO (&rfds);
|
||||
FD_SET (STDIN_FILENO, &rfds);
|
||||
if (!stdin_eof)
|
||||
{
|
||||
FD_SET (STDIN_FILENO, &rfds);
|
||||
}
|
||||
|
||||
retval = select (1, &rfds, NULL, NULL, &tv);
|
||||
|
||||
|
@ -281,13 +285,21 @@ bool FTTYStartupScreen::NetLoop(bool (*timer_callback)(void *), void *userdata)
|
|||
return true;
|
||||
}
|
||||
}
|
||||
else if (read (STDIN_FILENO, &k, 1) == 1)
|
||||
else
|
||||
{
|
||||
// Check input on stdin
|
||||
if (k == 'q' || k == 'Q')
|
||||
ssize_t amt = read (STDIN_FILENO, &k, 1); // Check input on stdin
|
||||
if (amt == 0)
|
||||
{
|
||||
fprintf (stderr, "\nNetwork game synchronization aborted.");
|
||||
return false;
|
||||
// EOF. Stop reading
|
||||
stdin_eof = true;
|
||||
}
|
||||
else if (amt == 1)
|
||||
{
|
||||
if (k == 'q' || k == 'Q')
|
||||
{
|
||||
fprintf (stderr, "\nNetwork game synchronization aborted.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue