Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

unix: clean up udp shutdown sequence

  • Loading branch information...
bnoordhuis committed Jan 18, 2012
1 parent ee10cb7 commit 28b0867f0312e3ccdc45d7fde0218d065ed40c65
Showing with 17 additions and 21 deletions.
  1. +2 −10 src/unix/core.c
  2. +2 −2 src/unix/internal.h
  3. +13 −9 src/unix/udp.c
@@ -64,7 +64,6 @@ static void uv__finish_close(uv_handle_t* handle);


void uv_close(uv_handle_t* handle, uv_close_cb close_cb) {
uv_udp_t* udp;
uv_async_t* async;
uv_timer_t* timer;
uv_stream_t* stream;
@@ -97,11 +96,7 @@ void uv_close(uv_handle_t* handle, uv_close_cb close_cb) {
break;

case UV_UDP:
udp = (uv_udp_t*)handle;
uv__udp_watcher_stop(udp, &udp->read_watcher);
uv__udp_watcher_stop(udp, &udp->write_watcher);
uv__close(udp->fd);
udp->fd = -1;
uv__udp_start_close((uv_udp_t*)handle);
break;

case UV_PREPARE:
@@ -278,10 +273,7 @@ void uv__finish_close(uv_handle_t* handle) {
break;

case UV_UDP:
assert(!ev_is_active(&((uv_udp_t*)handle)->read_watcher));
assert(!ev_is_active(&((uv_udp_t*)handle)->write_watcher));
assert(((uv_udp_t*)handle)->fd == -1);
uv__udp_destroy((uv_udp_t*)handle);
uv__udp_finish_close((uv_udp_t*)handle);
break;

case UV_PROCESS:
@@ -196,8 +196,8 @@ void uv__pipe_accept(EV_P_ ev_io* watcher, int revents);
int uv_pipe_cleanup(uv_pipe_t* handle);

/* udp */
void uv__udp_destroy(uv_udp_t* handle);
void uv__udp_watcher_stop(uv_udp_t* handle, ev_io* w);
void uv__udp_start_close(uv_udp_t* handle);
void uv__udp_finish_close(uv_udp_t* handle);

/* fs */
void uv__fs_event_destroy(uv_fs_event_t* handle);
@@ -79,10 +79,22 @@ void uv__udp_watcher_stop(uv_udp_t* handle, ev_io* w) {
}


void uv__udp_destroy(uv_udp_t* handle) {
void uv__udp_start_close(uv_udp_t* handle) {
uv__udp_watcher_stop(handle, &handle->read_watcher);
uv__udp_watcher_stop(handle, &handle->write_watcher);
uv__close(handle->fd);
handle->fd = -1;
}


void uv__udp_finish_close(uv_udp_t* handle) {
uv_udp_send_t* req;
ngx_queue_t* q;

assert(!ev_is_active(&handle->write_watcher));
assert(!ev_is_active(&handle->read_watcher));
assert(handle->fd == -1);

uv__udp_run_completed(handle);

while (!ngx_queue_empty(&handle->write_queue)) {
@@ -102,14 +114,6 @@ void uv__udp_destroy(uv_udp_t* handle) {
handle->recv_cb = NULL;
handle->alloc_cb = NULL;
/* but _do not_ touch close_cb */

if (handle->fd != -1) {
uv__close(handle->fd);
handle->fd = -1;
}

uv__udp_watcher_stop(handle, &handle->read_watcher);
uv__udp_watcher_stop(handle, &handle->write_watcher);
}


0 comments on commit 28b0867

Please sign in to comment.
You can’t perform that action at this time.