diff options
-rw-r--r-- | include/salticidae/event.h | 14 | ||||
-rw-r--r-- | src/conn.cpp | 3 |
2 files changed, 11 insertions, 6 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)>; diff --git a/src/conn.cpp b/src/conn.cpp index 5e663b6..98ad3fc 100644 --- a/src/conn.cpp +++ b/src/conn.cpp @@ -273,7 +273,7 @@ void ConnPool::disp_terminate(const conn_t &conn) { }); } -void ConnPool::accept_client(int fd, int events) { +void ConnPool::accept_client(int fd, int) { int client_fd; struct sockaddr client_addr; try { @@ -285,7 +285,6 @@ void ConnPool::accept_client(int fd, int events) { } else { - SALTICIDAE_LOG_INFO("%d\n", events); int one = 1; if (setsockopt(client_fd, SOL_TCP, TCP_NODELAY, (const char *)&one, sizeof(one)) < 0) throw ConnPoolError(SALTI_ERROR_ACCEPT, errno); |