diff options
author | Paul LeoNerd Evans <leonerd@leonerd.org.uk> | 2011-08-25 10:48:41 +0100 |
---|---|---|
committer | Paul LeoNerd Evans <leonerd@leonerd.org.uk> | 2011-08-25 10:48:41 +0100 |
commit | 1b8234e3425e518f40e00751cd0e5261649c166e (patch) | |
tree | 54c8fa53251ca96347721961da00aaa43f4c02ce /termkey.c | |
parent | 7a2b79a6402979b4895e78657d59a770d5b082b3 (diff) | |
download | termo-1b8234e3425e518f40e00751cd0e5261649c166e.tar.gz termo-1b8234e3425e518f40e00751cd0e5261649c166e.tar.xz termo-1b8234e3425e518f40e00751cd0e5261649c166e.zip |
Provide a flag to return RES_ERROR even on signal (EINTR); without it, retry the operation
Diffstat (limited to 'termkey.c')
-rw-r--r-- | termkey.c | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -841,12 +841,17 @@ TermKeyResult termkey_waitkey(TermKey *tk, TermKeyKey *key) struct pollfd fd; +retry: fd.fd = tk->fd; fd.events = POLLIN; int pollret = poll(&fd, 1, tk->waittime); - if(pollret == -1) + if(pollret == -1) { + if(errno == EINTR && !(tk->flags & TERMKEY_FLAG_EINTR)) + goto retry; + return TERMKEY_RES_ERROR; + } if(fd.revents & (POLLIN|POLLHUP|POLLERR)) ret = termkey_advisereadable(tk); @@ -884,11 +889,16 @@ void termkey_pushinput(TermKey *tk, const unsigned char *input, size_t inputlen) TermKeyResult termkey_advisereadable(TermKey *tk) { unsigned char buffer[64]; // Smaller than the default size - ssize_t len = read(tk->fd, buffer, sizeof buffer); + ssize_t len; + +retry: + len = read(tk->fd, buffer, sizeof buffer); if(len == -1) { if(errno == EAGAIN) return TERMKEY_RES_NONE; + else if(errno == EINTR && !(tk->flags & TERMKEY_FLAG_EINTR)) + goto retry; else return TERMKEY_RES_ERROR; } |