diff --git a/src/uv-common.c b/src/uv-common.c index 48f850c7..9639634a 100644 --- a/src/uv-common.c +++ b/src/uv-common.c @@ -22,6 +22,7 @@ #include "uv.h" #include "uv-common.h" +#include #include #include /* NULL */ #include /* malloc */ @@ -329,6 +330,50 @@ void uv_walk(uv_loop_t* loop, uv_walk_cb walk_cb, void* arg) { } +#ifndef NDEBUG +static void uv__print_handles(uv_loop_t* loop, int only_active) { + const char* type; + ngx_queue_t* q; + uv_handle_t* h; + + if (loop == NULL) + loop = uv_default_loop(); + + ngx_queue_foreach(q, &loop->handle_queue) { + h = ngx_queue_data(q, uv_handle_t, handle_queue); + + if (only_active && !uv__is_active(h)) + continue; + + switch (h->type) { +#define X(uc, lc) case UV_##uc: type = #lc; break; + UV_HANDLE_TYPE_MAP(X) +#undef X + default: type = ""; + } + + fprintf(stderr, + "[%c%c%c] %-8s %p\n", + "R-"[!(h->flags & UV__HANDLE_REF)], + "A-"[!(h->flags & UV__HANDLE_ACTIVE)], + "I-"[!(h->flags & UV__HANDLE_INTERNAL)], + type, + (void*)h); + } +} + + +void uv_print_all_handles(uv_loop_t* loop) { + uv__print_handles(loop, 0); +} + + +void uv_print_active_handles(uv_loop_t* loop) { + uv__print_handles(loop, 1); +} +#endif + + void uv_ref(uv_handle_t* handle) { uv__handle_ref(handle); }