aboutsummaryrefslogtreecommitdiffstats
path: root/iolooper-select.c
diff options
context:
space:
mode:
authorDavid 'Digit' Turner <digit@android.com>2010-11-18 16:10:45 +0100
committerDavid 'Digit' Turner <digit@android.com>2010-11-19 14:51:17 +0100
commit1bb627cd086588d3f9650fac04f4034961caf9f1 (patch)
tree2f12b3074cd6314f9556d21f074508d66c03d971 /iolooper-select.c
parent3aa86ac4b79c71e443d3010a84bed1da27f48880 (diff)
downloadexternal_qemu-1bb627cd086588d3f9650fac04f4034961caf9f1.zip
external_qemu-1bb627cd086588d3f9650fac04f4034961caf9f1.tar.gz
external_qemu-1bb627cd086588d3f9650fac04f4034961caf9f1.tar.bz2
Fix generic looper implementation
+ allow looper_run() to return a value that indicates why it exited. + add looper_runWithDeadline() and looper_runWithTimeout() in the case where you want to run only for a limited time. looper_runWithTimeout(looper,0) can be used to poll the event state and return asap after firing all the callbacks. + fix iolooper_modify() Change-Id: Iba3b0385a7fd8d90f4f3334ebf313e79267f7b3d
Diffstat (limited to 'iolooper-select.c')
-rw-r--r--iolooper-select.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/iolooper-select.c b/iolooper-select.c
index dc5257c..955204d 100644
--- a/iolooper-select.c
+++ b/iolooper-select.c
@@ -67,15 +67,15 @@ iolooper_modify( IoLooper* iol, int fd, int oldflags, int newflags )
if ((changed & IOLOOPER_READ) != 0) {
if ((newflags & IOLOOPER_READ) != 0)
- FD_SET(fd, iol->reads);
+ iolooper_add_read(iol, fd);
else
- FD_CLR(fd, iol->reads);
+ iolooper_del_read(iol, fd);
}
if ((changed & IOLOOPER_WRITE) != 0) {
if ((newflags & IOLOOPER_WRITE) != 0)
- FD_SET(fd, iol->writes);
+ iolooper_add_write(iol, fd);
else
- FD_CLR(fd, iol->writes);
+ iolooper_del_write(iol, fd);
}
}
@@ -230,5 +230,11 @@ int
iolooper_wait_absolute(IoLooper* iol, int64_t deadline)
{
int64_t timeout = deadline - iolooper_now();
- return (timeout >= 0) ? iolooper_wait(iol, timeout) : 0;
+
+ /* If the deadline has passed, set the timeout to 0, this allows us
+ * to poll the file descriptor nonetheless */
+ if (timeout < 0)
+ timeout = 0;
+
+ return iolooper_wait(iol, timeout);
}