From 2c7c345c987b3af041e2ef8b307fd1a654f1e501 Mon Sep 17 00:00:00 2001 From: Ali Gholami Rudi Date: Sat, 18 Jul 2009 20:15:28 +0430 Subject: [PATCH] term: wait for input if not available --- term.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/term.c b/term.c index 0c7fee2..bbd0512 100644 --- a/term.c +++ b/term.c @@ -1,5 +1,7 @@ #include +#include #include +#include #include #include #include @@ -139,11 +141,24 @@ static void setsize(void) static char ptybuf[PTYBUFSIZE]; static int ptylen; static int ptycur; +static void waitpty(void) +{ + struct pollfd ufds[1]; + ufds[0].fd = term->fd; + ufds[0].events = POLLIN; + poll(ufds, 1, -1); +} + static int readpty(void) { if (ptycur < ptylen) return ptybuf[ptycur++]; - if ((ptylen = read(term->fd, ptybuf, PTYBUFSIZE)) > 0) { + ptylen = read(term->fd, ptybuf, PTYBUFSIZE); + if (ptylen == -1 && errno == EAGAIN) { + waitpty(); + ptylen = read(term->fd, ptybuf, PTYBUFSIZE); + } + if (ptylen > 0) { ptycur = 1; return ptybuf[0]; } -- 2.11.4.GIT