diff options
author | Uoti Urpala <uau@mplayer2.org> | 2012-04-06 14:24:26 +0300 |
---|---|---|
committer | Uoti Urpala <uau@mplayer2.org> | 2012-04-06 14:34:56 +0300 |
commit | b93ed278362185ff980e0ce8f4ab3029f8fe395f (patch) | |
tree | b0915d50baa17cc7ab94180421f8837f7b5b3ee4 /osdep/getch2.c | |
parent | 87ae9d3e45ef6e331b34fa92ac1d0c68495f5379 (diff) | |
download | mpv-b93ed278362185ff980e0ce8f4ab3029f8fe395f.tar.bz2 mpv-b93ed278362185ff980e0ce8f4ab3029f8fe395f.tar.xz |
input: stop trying to read terminal input on EOF
Stop trying to read terminal input if a read attempt returns EOF. The
most important case where this matters is when someone runs the player
with stdin redirected from /dev/null and without specifying
--no-consolecontrols. This used to cause 100% CPU load while paused,
as select() would continuously trigger on stdin (the need for
--no-consolecontrols was not apparent to people with older mplayer
versions, as input reading was less efficient and latencies like
hardcoded sleeps kept CPU use well below 100%). Now this will only
cause a "Dead key input" error message.
Diffstat (limited to 'osdep/getch2.c')
-rw-r--r-- | osdep/getch2.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/osdep/getch2.c b/osdep/getch2.c index 1a92866afd..dcd5b1ad84 100644 --- a/osdep/getch2.c +++ b/osdep/getch2.c @@ -158,11 +158,17 @@ void get_screen_size(void){ #endif } -void getch2(struct mp_fifo *fifo) +bool getch2(struct mp_fifo *fifo) { int retval = read(0, &getch2_buf[getch2_len], BUF_LEN-getch2_len); + /* Return false on EOF to stop running select() on the FD, as it'd + * trigger all the time. Note that it's possible to get temporary + * EOF on terminal if the user presses ctrl-d, but that shouldn't + * happen if the terminal state change done in getch2_enable() + * works. + */ if (retval < 1) - return; + return retval; getch2_len += retval; while (getch2_len > 0 && (getch2_len > 1 || getch2_buf[0] != 27)) { @@ -279,6 +285,7 @@ void getch2(struct mp_fifo *fifo) getch2_buf[i] = getch2_buf[len+i]; mplayer_put_key(fifo, code); } + return true; } static int getch2_status=0; |