From 0ecefd5bf91ae8297569dc862d7259e942d895fe Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 31 Aug 2016 15:39:59 +0200 Subject: [PATCH] tevent: Add tevent_update_timer() 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 Reviewed-by: Jeremy Allison --- lib/tevent/ABI/tevent-0.9.30.sigs | 1 + lib/tevent/tevent.h | 10 ++++++++++ lib/tevent/tevent_timed.c | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/lib/tevent/ABI/tevent-0.9.30.sigs b/lib/tevent/ABI/tevent-0.9.30.sigs index 9b8bfa1cedd..66a450e1545 100644 --- a/lib/tevent/ABI/tevent-0.9.30.sigs +++ b/lib/tevent/ABI/tevent-0.9.30.sigs @@ -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) diff --git a/lib/tevent/tevent.h b/lib/tevent/tevent.h index 7de04d03896..bb23257a965 100644 --- a/lib/tevent/tevent.h +++ b/lib/tevent/tevent.h @@ -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 diff --git a/lib/tevent/tevent_timed.c b/lib/tevent/tevent_timed.c index bb0160c41e4..92f3ed17b26 100644 --- a/lib/tevent/tevent_timed.c +++ b/lib/tevent/tevent_timed.c @@ -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 -- 2.11.4.GIT