tevent: add tevent_common_loop_wait() helper function and use it
[ira/wip.git] / lib / tevent / tevent.c
index 867cfc08feff88c3532a98f76c94d1f5b8fb0e47..31dc58d98e8c42cb2a453fa793e357f44170bd8c 100644 (file)
@@ -511,6 +511,34 @@ done:
        return ret;
 }
 
+/*
+  return on failure or (with 0) if all fd events are removed
+*/
+int tevent_common_loop_wait(struct tevent_context *ev,
+                           const char *location)
+{
+       /*
+        * loop as long as we have events pending
+        */
+       while (ev->fd_events ||
+              ev->timer_events ||
+              ev->immediate_events ||
+              ev->signal_events) {
+               int ret;
+               ret = _tevent_loop_once(ev, location);
+               if (ret != 0) {
+                       tevent_debug(ev, TEVENT_DEBUG_FATAL,
+                                    "_tevent_loop_once() failed: %d - %s\n",
+                                    ret, strerror(errno));
+                       return ret;
+               }
+       }
+
+       tevent_debug(ev, TEVENT_DEBUG_WARNING,
+                    "tevent_common_loop_wait() out of events\n");
+       return 0;
+}
+
 /*
   return on failure or (with 0) if all fd events are removed
 */