diff options
author | Determinant <[email protected]> | 2019-07-04 13:30:23 -0400 |
---|---|---|
committer | Determinant <[email protected]> | 2019-07-04 13:30:23 -0400 |
commit | 384d9277458cbd90c94d1510e5d20d96b26010c8 (patch) | |
tree | a93fd327093fedfdfccd947fbc3887084f03e880 /include | |
parent | 69a9bed21f18728483320e88530045180796e2ac (diff) |
improve EventContext deleter
Diffstat (limited to 'include')
-rw-r--r-- | include/salticidae/event.h | 14 |
1 files changed, 10 insertions, 4 deletions
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<void(int fd, int events)>; |