diff options
author | Paul LeoNerd Evans <leonerd@leonerd.org.uk> | 2008-11-03 21:08:34 +0000 |
---|---|---|
committer | Paul LeoNerd Evans <leonerd@leonerd.org.uk> | 2008-11-03 21:08:34 +0000 |
commit | 76147e92d4bd12c27ef56d8ab9b1203ee3eeb927 (patch) | |
tree | 74424018074a075e4225215f47fe637baa548275 | |
parent | 86933f18364a249ca67b4b916e83edbb429e091f (diff) | |
download | termo-76147e92d4bd12c27ef56d8ab9b1203ee3eeb927.tar.gz termo-76147e92d4bd12c27ef56d8ab9b1203ee3eeb927.tar.xz termo-76147e92d4bd12c27ef56d8ab9b1203ee3eeb927.zip |
Better handling in termkey_waitkey() of EOF conditions
-rw-r--r-- | termkey.c | 16 |
1 files changed, 12 insertions, 4 deletions
@@ -510,17 +510,25 @@ termkey_result termkey_waitkey(termkey_t *tk, termkey_key *key) 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; fd.fd = tk->fd; fd.events = POLLIN; - int pollres = poll(&fd, 1, tk->waittime); + poll(&fd, 1, tk->waittime); - if(pollres == 0) - return termkey_getkey_force(tk, key); + if(fd.revents & (POLLIN|POLLHUP|POLLERR)) + ret = termkey_advisereadable(tk); + else + ret = TERMKEY_RES_NONE; - termkey_advisereadable(tk); + if(ret == TERMKEY_RES_NONE) + return termkey_getkey_force(tk, key); } break; } |