Better handling in termkey_waitkey() of EOF conditions

This commit is contained in:
Paul LeoNerd Evans 2008-11-03 21:08:34 +00:00
parent 86933f1836
commit 76147e92d4
1 changed files with 12 additions and 4 deletions

View File

@ -510,17 +510,25 @@ termkey_result termkey_waitkey(termkey_t *tk, termkey_key *key)
case TERMKEY_RES_AGAIN: case TERMKEY_RES_AGAIN:
{ {
if(tk->is_closed)
// We're closed now. Never going to get more bytes so just go with
// what we have
return termkey_getkey_force(tk, key);
struct pollfd fd; struct pollfd fd;
fd.fd = tk->fd; fd.fd = tk->fd;
fd.events = POLLIN; fd.events = POLLIN;
int pollres = poll(&fd, 1, tk->waittime); poll(&fd, 1, tk->waittime);
if(pollres == 0) if(fd.revents & (POLLIN|POLLHUP|POLLERR))
ret = termkey_advisereadable(tk);
else
ret = TERMKEY_RES_NONE;
if(ret == TERMKEY_RES_NONE)
return termkey_getkey_force(tk, key); return termkey_getkey_force(tk, key);
termkey_advisereadable(tk);
} }
break; break;
} }