tevent: Add tevent_update_timer()
authorVolker Lendecke <vl@samba.org>
Wed, 31 Aug 2016 13:39:59 +0000 (15:39 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 4 Oct 2016 22:06:21 +0000 (00:06 +0200)
This will be a quicker way to time out sending sockets in messaging_dgm. Right
now cleanup of out-sockets is a bit coarse. The ideal would be to kill a socket
after being idle n seconds. This would mean to free and re-install a timer on
every packet. tevent_update_timer will be quite a bit cheaper.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
lib/tevent/ABI/tevent-0.9.30.sigs
lib/tevent/tevent.h
lib/tevent/tevent_timed.c

index 9b8bfa1cedd88620956e7415b4d127edc8d58395..66a450e15457b21754f31e4338bba7911f7fae9a 100644 (file)
@@ -92,5 +92,6 @@ tevent_timeval_set: struct timeval (uint32_t, uint32_t)
 tevent_timeval_until: struct timeval (const struct timeval *, const struct timeval *)
 tevent_timeval_zero: struct timeval (void)
 tevent_trace_point_callback: void (struct tevent_context *, enum tevent_trace_point)
+tevent_update_timer: void (struct tevent_timer *, struct timeval)
 tevent_wakeup_recv: bool (struct tevent_req *)
 tevent_wakeup_send: struct tevent_req *(TALLOC_CTX *, struct tevent_context *, struct timeval)
index 7de04d03896c17958d1ad9cc94a3bfdae44dedf2..bb23257a9656ae74e3342024729316ad2b69d534 100644 (file)
@@ -252,6 +252,16 @@ struct tevent_timer *_tevent_add_timer(struct tevent_context *ev,
                          #handler, __location__)
 #endif
 
+/**
+ * @brief Set the time a tevent_timer fires
+ *
+ * @param[in]  te       The timer event to reset
+ *
+ * @param[in]  next_event  Timeval specifying the absolute time to fire this
+ * event. This is not an offset.
+ */
+void tevent_update_timer(struct tevent_timer *te, struct timeval next_event);
+
 #ifdef DOXYGEN
 /**
  * Initialize an immediate event object
index bb0160c41e43e6e8a7c006b295ae55016dcfee5d..92f3ed17b26ee749de270af3b4411a79af21de86 100644 (file)
@@ -284,6 +284,24 @@ struct tevent_timer *tevent_common_add_timer_v2(struct tevent_context *ev,
                                                true);
 }
 
+void tevent_update_timer(struct tevent_timer *te, struct timeval next_event)
+{
+       struct tevent_context *ev = te->event_ctx;
+
+       if (ev->last_zero_timer == te) {
+               te->event_ctx->last_zero_timer = DLIST_PREV(te);
+       }
+       DLIST_REMOVE(ev->timer_events, te);
+
+       te->next_event = next_event;
+
+       /*
+        * Not doing the zero_timer optimization. This is for new code
+        * that should know about immediates.
+        */
+       tevent_common_insert_timer(ev, te, false);
+}
+
 /*
   do a single event loop using the events defined in ev