diff --git a/src/unix/core.c b/src/unix/core.c index 22370708..bfdade3d 100644 --- a/src/unix/core.c +++ b/src/unix/core.c @@ -65,6 +65,9 @@ static uv_loop_t* default_loop_ptr; void uv_close(uv_handle_t* handle, uv_close_cb close_cb) { + assert(!(handle->flags & (UV_CLOSING | UV_CLOSED))); + + handle->flags |= UV_CLOSING; handle->close_cb = close_cb; switch (handle->type) { @@ -128,8 +131,13 @@ void uv_close(uv_handle_t* handle, uv_close_cb close_cb) { assert(0); } - handle->flags |= UV_CLOSING; + uv__make_close_pending(handle); +} + +void uv__make_close_pending(uv_handle_t* handle) { + assert(handle->flags & UV_CLOSING); + assert(!(handle->flags & UV_CLOSED)); handle->next_closing = handle->loop->closing_handles; handle->loop->closing_handles = handle; } diff --git a/src/unix/internal.h b/src/unix/internal.h index 23266764..ed8dedcf 100644 --- a/src/unix/internal.h +++ b/src/unix/internal.h @@ -115,6 +115,7 @@ int uv__cloexec(int fd, int set); int uv__socket(int domain, int type, int protocol); int uv__dup(int fd); int uv_async_stop(uv_async_t* handle); +void uv__make_close_pending(uv_handle_t* handle); void uv__io_init(uv__io_t* handle, uv__io_cb cb, int fd, int events); void uv__io_set(uv__io_t* handle, uv__io_cb cb, int fd, int events);