aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2019-07-04 13:30:23 -0400
committerDeterminant <[email protected]>2019-07-04 13:30:23 -0400
commit384d9277458cbd90c94d1510e5d20d96b26010c8 (patch)
treea93fd327093fedfdfccd947fbc3887084f03e880
parent69a9bed21f18728483320e88530045180796e2ac (diff)
improve EventContext deleter
-rw-r--r--include/salticidae/event.h14
-rw-r--r--src/conn.cpp3
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);