unix: make it possible to delay close callbacks

This commit is contained in:
Bert Belder 2012-10-16 17:30:30 +02:00
parent 47eb03490a
commit 39d574dcff
2 changed files with 10 additions and 1 deletions

View File

@ -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;
}

View File

@ -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);