From 83becbe369bcf3478063662fc2626ccbf4530b20 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 8 Feb 2011 17:28:27 +0100 Subject: s3: Add sys_poll_intr --- lib/util/select.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'lib/util/select.c') diff --git a/lib/util/select.c b/lib/util/select.c index b40538c473..5f1c91cff6 100644 --- a/lib/util/select.c +++ b/lib/util/select.c @@ -286,3 +286,29 @@ int sys_poll(struct pollfd *fds, int num_fds, int timeout) return ret; } + +int sys_poll_intr(struct pollfd *fds, int num_fds, int timeout) +{ + int orig_timeout = timeout; + struct timespec start; + int ret; + + clock_gettime_mono(&start); + + while (true) { + struct timespec now; + int64_t elapsed; + + ret = poll(fds, num_fds, timeout); + if (ret != -1) { + break; + } + if (errno != EINTR) { + break; + } + clock_gettime_mono(&now); + elapsed = nsec_time_diff(&now, &start); + timeout = (orig_timeout - elapsed) / 1000000; + }; + return ret; +} -- cgit