From 384d9277458cbd90c94d1510e5d20d96b26010c8 Mon Sep 17 00:00:00 2001 From: Determinant Date: Thu, 4 Jul 2019 13:30:23 -0400 Subject: improve EventContext deleter --- include/salticidae/event.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/salticidae/event.h b/include/salticidae/event.h index 420c073..2f22e1a 100644 --- a/include/salticidae/event.h +++ b/include/salticidae/event.h @@ -38,13 +38,21 @@ namespace salticidae { +static void _on_uv_handle_close(uv_handle_t *h) { if (h) delete h; } + struct _event_context_deleter { constexpr _event_context_deleter() = default; + static void _on_uv_walk(uv_handle_t *handle, void *) { + if (!uv_is_closing(handle)) + uv_close(handle, _on_uv_handle_close); + } void operator()(uv_loop_t *ptr) { if (ptr != nullptr) { - while (uv_loop_close(ptr) == UV_EBUSY) - uv_run(ptr, UV_RUN_NOWAIT); + uv_walk(ptr, _on_uv_walk, nullptr); + uv_run(ptr, UV_RUN_DEFAULT); + if (uv_loop_close(ptr)) + SALTICIDAE_LOG_WARN("failed to close libuv loop"); delete ptr; } } @@ -74,8 +82,6 @@ class EventContext: public _event_context_ot { void stop() const { uv_stop(get()); } }; -static void _on_uv_handle_close(uv_handle_t *h) { delete h; } - class FdEvent { public: using callback_t = std::function; -- cgit v1.2.3-70-g09d2