select: epoll: Recompute timeout after EINTR.

As detailed in PEP 475, timeout should be recomputed before retrying
the interrupted system call.
pull/222/head
Reid Wagner 2017-10-08 11:39:08 -07:00 zatwierdzone przez Paul Sokolovsky
rodzic c8f9cf1dca
commit c09b364253
1 zmienionych plików z 8 dodań i 1 usunięć

Wyświetl plik

@ -3,6 +3,7 @@ import ustruct as struct
import os import os
import errno import errno
import ffilib import ffilib
import utime
from uselect import * from uselect import *
@ -73,11 +74,17 @@ class Epoll:
def poll_ms(self, timeout=-1): def poll_ms(self, timeout=-1):
s = bytearray(self.evbuf) s = bytearray(self.evbuf)
if timeout >= 0:
deadline = utime.ticks_add(utime.ticks_ms(), timeout)
while True: while True:
n = epoll_wait(self.epfd, s, 1, timeout) n = epoll_wait(self.epfd, s, 1, timeout)
if not os.check_error(n): if not os.check_error(n):
break break
# TODO: what about timeout value? if timeout >= 0:
timeout = utime.ticks_diff(deadline, utime.ticks_ms())
if timeout < 0:
n = 0
break
res = [] res = []
if n > 0: if n > 0:
vals = struct.unpack(epoll_event, s) vals = struct.unpack(epoll_event, s)