diff options
author | Vladimir Chtchetkine <vchtchetkine@google.com> | 2010-11-16 08:20:19 -0800 |
---|---|---|
committer | Android Code Review <code-review@android.com> | 2010-11-16 08:20:19 -0800 |
commit | 44e750e6d0375543f0d91d0a68432ae9c8489ccd (patch) | |
tree | dbb6bd7366d499b7396388169f3703cac329df33 /iolooper-select.c | |
parent | 26a57c423b35f84628542e82ad482fb1c55a2368 (diff) | |
parent | d8ba2ae8942abd9757338fc110ce6d215c486b1c (diff) | |
download | external_qemu-44e750e6d0375543f0d91d0a68432ae9c8489ccd.zip external_qemu-44e750e6d0375543f0d91d0a68432ae9c8489ccd.tar.gz external_qemu-44e750e6d0375543f0d91d0a68432ae9c8489ccd.tar.bz2 |
Merge "Implement absoule wait in iolooper"
Diffstat (limited to 'iolooper-select.c')
-rw-r--r-- | iolooper-select.c | 19 |
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; +} |