Handle errno better when polling for events

This commit is contained in:
Kovid Goyal 2018-07-13 10:33:18 +05:30
parent 037bfeff82
commit 31853ee20c
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -222,7 +222,9 @@ pollForEvents(EventLoopData *eld, double timeout) {
while(1) {
if (timeout >= 0) {
errno = 0;
result = pollWithTimeout(eld->fds, eld->watches_count, timeout);
int saved_errno = errno;
dispatchTimers(eld);
if (result > 0) {
dispatchEvents(eld);
@ -231,16 +233,18 @@ pollForEvents(EventLoopData *eld, double timeout) {
}
timeout = end_time - monotonic();
if (timeout <= 0) break;
if (result < 0 && (errno == EINTR || errno == EAGAIN)) continue;
if (result < 0 && (saved_errno == EINTR || saved_errno == EAGAIN)) continue;
break;
} else {
errno = 0;
result = poll(eld->fds, eld->watches_count, -1);
int saved_errno = errno;
dispatchTimers(eld);
if (result > 0) {
dispatchEvents(eld);
read_ok = eld->watches[0].ready;
}
if (result < 0 && (errno == EINTR || errno == EAGAIN)) continue;
if (result < 0 && (saved_errno == EINTR || saved_errno == EAGAIN)) continue;
break;
}
}