From 1bb627cd086588d3f9650fac04f4034961caf9f1 Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Thu, 18 Nov 2010 16:10:45 +0100 Subject: 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 --- iolooper-select.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'iolooper-select.c') 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); } -- cgit v1.1