Permalink
Browse files

Cherry-pick of bnoordhuis/libuv@ae6bd75

  • Loading branch information...
1 parent 69ce415 commit a3ede6024db4aa3dc38994cb114fdfb5625fa3a1 @bnoordhuis committed Aug 6, 2011
Showing with 19 additions and 28 deletions.
  1. +19 −28 deps/uv/src/uv-unix.c
View
@@ -213,19 +213,31 @@ static uv_err_t uv_err_new(uv_handle_t* handle, int sys_error) {
void uv_close(uv_handle_t* handle, uv_close_cb close_cb) {
- uv_tcp_t* tcp;
- uv_pipe_t* pipe;
uv_async_t* async;
uv_timer_t* timer;
+ uv_stream_t* stream;
uv_process_t* process;
handle->close_cb = close_cb;
switch (handle->type) {
+ case UV_NAMED_PIPE:
+ uv_pipe_cleanup((uv_pipe_t*)handle);
+ /* Fall through. */
+
case UV_TCP:
- tcp = (uv_tcp_t*) handle;
- uv_read_stop((uv_stream_t*)tcp);
- ev_io_stop(EV_DEFAULT_ &tcp->write_watcher);
+ stream = (uv_stream_t*)handle;
+
+ uv_read_stop(stream);
+ ev_io_stop(EV_DEFAULT_ &stream->write_watcher);
+
+ uv__close(stream->fd);
+ stream->fd = -1;
+
+ if (stream->accepted_fd >= 0) {
+ uv__close(stream->accepted_fd);
+ stream->accepted_fd = -1;
+ }
break;
case UV_PREPARE:
@@ -254,13 +266,6 @@ void uv_close(uv_handle_t* handle, uv_close_cb close_cb) {
ev_timer_stop(EV_DEFAULT_ &timer->timer_watcher);
break;
- case UV_NAMED_PIPE:
- pipe = (uv_pipe_t*)handle;
- uv_pipe_cleanup(pipe);
- uv_read_stop((uv_stream_t*)handle);
- ev_io_stop(EV_DEFAULT_ &pipe->write_watcher);
- break;
-
case UV_PROCESS:
process = (uv_process_t*)handle;
ev_child_stop(EV_DEFAULT_UC_ &process->child_watcher);
@@ -588,23 +593,9 @@ void uv__finish_close(uv_handle_t* handle) {
case UV_NAMED_PIPE:
case UV_TCP:
- {
- uv_stream_t* stream;
-
- stream = (uv_stream_t*)handle;
-
- assert(!ev_is_active(&stream->read_watcher));
- assert(!ev_is_active(&stream->write_watcher));
-
- uv__close(stream->fd);
- stream->fd = -1;
-
- if (stream->accepted_fd >= 0) {
- uv__close(stream->accepted_fd);
- stream->accepted_fd = -1;
- }
+ assert(!ev_is_active(&((uv_stream_t*)handle)->read_watcher));
+ assert(!ev_is_active(&((uv_stream_t*)handle)->write_watcher));
break;
- }
case UV_PROCESS:
assert(!ev_is_active(&((uv_process_t*)handle)->child_watcher));

0 comments on commit a3ede60

Please sign in to comment.