diff options
author | Uoti Urpala <uau@mplayer2.org> | 2011-04-28 12:52:00 +0300 |
---|---|---|
committer | Uoti Urpala <uau@mplayer2.org> | 2011-04-28 12:52:00 +0300 |
commit | 40234b1a3c21cd0ef1087bd5b5e9601dd56c4fce (patch) | |
tree | 22cdc7fb6ddd5222753366eab8dadad8ed768005 /osdep | |
parent | 3b401fb07f04dd1947402550db6702619bbcb5ce (diff) | |
download | mpv-40234b1a3c21cd0ef1087bd5b5e9601dd56c4fce.tar.bz2 mpv-40234b1a3c21cd0ef1087bd5b5e9601dd56c4fce.tar.xz |
input: make stdin non-blocking for terminal input
getch2.c did not make stdin non-blocking, and relied on only being
called after select() had shown readability. Stop relying on that
assumption and set stdin to non-blocking mode. Hopefully no relevant
platform has problems with this...
Diffstat (limited to 'osdep')
-rw-r--r-- | osdep/getch2.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/osdep/getch2.c b/osdep/getch2.c index 4aa09323eb..3369838682 100644 --- a/osdep/getch2.c +++ b/osdep/getch2.c @@ -55,6 +55,7 @@ #endif #include <unistd.h> +#include <fcntl.h> #include "mp_fifo.h" #include "keycodes.h" @@ -277,10 +278,15 @@ struct termios tio_new; tcgetattr(0,&tio_orig); tio_new=tio_orig; tio_new.c_lflag &= ~(ICANON|ECHO); /* Clear ICANON and ECHO. */ - tio_new.c_cc[VMIN] = 1; + tio_new.c_cc[VMIN] = 0; tio_new.c_cc[VTIME] = 0; tcsetattr(0,TCSANOW,&tio_new); #endif + /* Setting VMIN above should already make terminal non-blocking; but + * that won't work if stdin is not a real terminal. */ + int flags = fcntl(0, F_GETFL); + if (flags != -1) + fcntl(0, F_SETFL, flags | O_NONBLOCK); getch2_status=1; } |