uloop: allow passing 0 as timeout to uloop_run
[project/libubox.git] / uloop.c
diff --git a/uloop.c b/uloop.c
index 26fef32bd67b1818617e3b88ecaf34292badf0e5..d2f41bbfd1c8cc995f5416f287597774341a6190 100644 (file)
--- a/uloop.c
+++ b/uloop.c
@@ -520,8 +520,9 @@ bool uloop_cancelling(void)
        return uloop_run_depth > 0 && uloop_cancelled;
 }
 
-int uloop_run(void)
+int uloop_run_timeout(int timeout)
 {
+       int next_time = 0;
        struct timeval tv;
 
        /*
@@ -545,7 +546,11 @@ int uloop_run(void)
                        break;
 
                uloop_gettime(&tv);
-               uloop_run_events(uloop_get_next_timeout(&tv));
+
+               next_time = uloop_get_next_timeout(&tv);
+               if (timeout >= 0 && timeout < next_time)
+                       next_time = timeout;
+               uloop_run_events(next_time);
        }
 
        if (!--uloop_run_depth)