From 1b8234e3425e518f40e00751cd0e5261649c166e Mon Sep 17 00:00:00 2001 From: Paul LeoNerd Evans Date: Thu, 25 Aug 2011 10:48:41 +0100 Subject: Provide a flag to return RES_ERROR even on signal (EINTR); without it, retry the operation --- termkey.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'termkey.c') 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; } -- cgit v1.2.3-70-g09d2