From c09b3642530563bc35c7c3355e5cd49170ff9ad6 Mon Sep 17 00:00:00 2001 From: Reid Wagner Date: Sun, 8 Oct 2017 11:39:08 -0700 Subject: [PATCH] select: epoll: Recompute timeout after EINTR. As detailed in PEP 475, timeout should be recomputed before retrying the interrupted system call. --- select/select.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/select/select.py b/select/select.py index 7fa801b4..72d125d1 100644 --- a/select/select.py +++ b/select/select.py @@ -3,6 +3,7 @@ import ustruct as struct import os import errno import ffilib +import utime from uselect import * @@ -73,11 +74,17 @@ class Epoll: def poll_ms(self, timeout=-1): s = bytearray(self.evbuf) + if timeout >= 0: + deadline = utime.ticks_add(utime.ticks_ms(), timeout) while True: n = epoll_wait(self.epfd, s, 1, timeout) if not os.check_error(n): break - # TODO: what about timeout value? + if timeout >= 0: + timeout = utime.ticks_diff(deadline, utime.ticks_ms()) + if timeout < 0: + n = 0 + break res = [] if n > 0: vals = struct.unpack(epoll_event, s)