Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
unix: clean up udp shutdown sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Jan 18, 2012
1 parent ee10cb7 commit 28b0867
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
12 changes: 2 additions & 10 deletions src/unix/core.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/unix/internal.h
Expand Up @@ -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);
Expand Down
22 changes: 13 additions & 9 deletions src/unix/udp.c
Expand Up @@ -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)) {
Expand All @@ -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);
}


Expand Down

0 comments on commit 28b0867

Please sign in to comment.