aboutsummaryrefslogtreecommitdiff
path: root/termkey.c
diff options
context:
space:
mode:
authorPaul LeoNerd Evans <leonerd@leonerd.org.uk>2011-08-25 10:48:41 +0100
committerPaul LeoNerd Evans <leonerd@leonerd.org.uk>2011-08-25 10:48:41 +0100
commit1b8234e3425e518f40e00751cd0e5261649c166e (patch)
tree54c8fa53251ca96347721961da00aaa43f4c02ce /termkey.c
parent7a2b79a6402979b4895e78657d59a770d5b082b3 (diff)
downloadtermo-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.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/termkey.c b/termkey.c
index dd1020b..921bb6c 100644
--- a/termkey.c
+++ b/termkey.c
@@ -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;
}