aboutsummaryrefslogtreecommitdiffstats
path: root/iolooper-select.c
diff options
context:
space:
mode:
authorVladimir Chtchetkine <vchtchetkine@google.com>2010-11-15 11:02:49 -0800
committerVladimir Chtchetkine <vchtchetkine@google.com>2010-11-16 08:19:43 -0800
commitd8ba2ae8942abd9757338fc110ce6d215c486b1c (patch)
treedbb6bd7366d499b7396388169f3703cac329df33 /iolooper-select.c
parentb94cfb86ee0337cf4454161798741076ee007688 (diff)
downloadexternal_qemu-d8ba2ae8942abd9757338fc110ce6d215c486b1c.zip
external_qemu-d8ba2ae8942abd9757338fc110ce6d215c486b1c.tar.gz
external_qemu-d8ba2ae8942abd9757338fc110ce6d215c486b1c.tar.bz2
Implement absoule wait in iolooper
Change-Id: I514ffe11bcdac2fe3c6b44998892d9a604b9966f
Diffstat (limited to 'iolooper-select.c')
-rw-r--r--iolooper-select.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/iolooper-select.c b/iolooper-select.c
index 000fa5d..62cce08 100644
--- a/iolooper-select.c
+++ b/iolooper-select.c
@@ -166,6 +166,10 @@ iolooper_wait( IoLooper* iol, int64_t duration )
iol->writes_result[0] = iol->writes[0];
ret = select( count, iol->reads_result, iol->writes_result, &errs, tm);
+ if (ret == 0) {
+ // Indicates timeout
+ errno = ETIMEDOUT;
+ }
} while (ret < 0 && errno == EINTR);
return ret;
@@ -189,3 +193,18 @@ iolooper_has_operations( IoLooper* iol )
{
return iolooper_fd_count(iol) > 0;
}
+
+int64_t
+iolooper_now(void)
+{
+ struct timeval time_now;
+ return gettimeofday(&time_now, NULL) ? -1 : (int64_t)time_now.tv_sec * 1000LL +
+ time_now.tv_usec / 1000;
+}
+
+int
+iolooper_wait_absolute(IoLooper* iol, int64_t deadline)
+{
+ int64_t timeout = deadline - iolooper_now();
+ return (timeout >= 0) ? iolooper_wait(iol, timeout) : 0;
+}