make the avl node key const
[project/libubox.git] / uloop.c
diff --git a/uloop.c b/uloop.c
index 8410634..f60eb41 100644 (file)
--- a/uloop.c
+++ b/uloop.c
@@ -121,7 +121,7 @@ static void uloop_run_events(int timeout)
 
        if (timeout > 0) {
                ts.tv_sec = timeout / 1000;
-               ts.tv_nsec = timeout * 1000000;
+               ts.tv_nsec = (timeout % 1000) * 1000000;
        }
 
        nfds = kevent(poll_fd, NULL, 0, events, ARRAY_SIZE(events), timeout > 0 ? &ts : NULL);
@@ -383,6 +383,8 @@ void uloop_run(void)
        {
                gettimeofday(&tv, NULL);
                uloop_process_timeouts(&tv);
+               if (uloop_cancelled)
+                       break;
                uloop_run_events(uloop_get_next_timeout(&tv));
        }
 }