uloop: add uloop_timeout_pending() function to determine the remaining time of an...
[project/libubox.git] / uloop.c
diff --git a/uloop.c b/uloop.c
index 4095d5b..3a62b62 100644 (file)
--- a/uloop.c
+++ b/uloop.c
@@ -387,6 +387,18 @@ int uloop_timeout_cancel(struct uloop_timeout *timeout)
        return 0;
 }
 
+int uloop_timeout_pending(struct uloop_timeout *timeout)
+{
+       struct timeval now;
+
+       if (!timeout->pending)
+               return -1;
+
+       uloop_gettime(&now);
+
+       return tv_diff(&timeout->time, &now);
+}
+
 int uloop_process_add(struct uloop_process *p)
 {
        struct uloop_process *tmp;