From 7584225873cd27b53f3fdfb6af5c12c6514acdfa Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Mon, 16 Jan 2012 15:15:34 -0800 Subject: [PATCH] Upgrade libuv to joyent/libuv@f5bd21f --- deps/uv/include/uv-private/ev.h | 2 + deps/uv/include/uv.h | 3 + deps/uv/src/unix/core.c | 11 +- deps/uv/src/unix/ev/ev.c | 6 ++ deps/uv/src/unix/udp.c | 12 ++- deps/uv/src/win/core.c | 5 + deps/uv/src/win/fs.c | 74 ++++++++++---- deps/uv/src/win/internal.h | 4 +- deps/uv/src/win/util.c | 23 +++++ deps/uv/test/echo-server.c | 64 ++++++++++++ deps/uv/test/task.h | 1 + deps/uv/test/test-eio-overflow.c | 4 +- deps/uv/test/test-fs-event.c | 18 ---- deps/uv/test/test-list.h | 46 ++++++--- deps/uv/test/test-ref.c | 169 +++++++++++++++++++++++++++++++ deps/uv/test/test-tcp-close.c | 47 --------- deps/uv/test/test-timer.c | 40 -------- 17 files changed, 377 insertions(+), 152 deletions(-) diff --git a/deps/uv/include/uv-private/ev.h b/deps/uv/include/uv-private/ev.h index 5d2d7a1e37..11e81cda5e 100644 --- a/deps/uv/include/uv-private/ev.h +++ b/deps/uv/include/uv-private/ev.h @@ -562,6 +562,8 @@ EV_MAYBE_UNUSED ev_is_default_loop (EV_P) /* create and destroy alternative loops that don't handle signals */ struct ev_loop *ev_loop_new (unsigned int flags EV_CPP (= 0)); +int ev_loop_refcount (EV_P); + ev_tstamp ev_now (EV_P); /* time w.r.t. timers and the eventloop, updated after each poll */ #else diff --git a/deps/uv/include/uv.h b/deps/uv/include/uv.h index 963411278f..09000a2cef 100644 --- a/deps/uv/include/uv.h +++ b/deps/uv/include/uv.h @@ -202,6 +202,9 @@ typedef struct uv_work_s uv_work_t; UV_EXTERN uv_loop_t* uv_loop_new(void); UV_EXTERN void uv_loop_delete(uv_loop_t*); +/* This is a debugging tool. It's NOT part of the official API. */ +UV_EXTERN int uv_loop_refcount(const uv_loop_t*); + /* * Returns the default loop. diff --git a/deps/uv/src/unix/core.c b/deps/uv/src/unix/core.c index 67e08976d3..55c7515224 100644 --- a/deps/uv/src/unix/core.c +++ b/deps/uv/src/unix/core.c @@ -63,12 +63,6 @@ void uv__next(EV_P_ ev_idle* watcher, int revents); static void uv__finish_close(uv_handle_t* handle); - -#ifndef __GNUC__ -#define __attribute__(a) -#endif - - void uv_close(uv_handle_t* handle, uv_close_cb close_cb) { uv_udp_t* udp; uv_async_t* async; @@ -202,6 +196,11 @@ void uv_loop_delete(uv_loop_t* loop) { } +int uv_loop_refcount(const uv_loop_t* loop) { + return ev_loop_refcount(loop->ev); +} + + uv_loop_t* uv_default_loop(void) { if (default_loop_ptr) return default_loop_ptr; diff --git a/deps/uv/src/unix/ev/ev.c b/deps/uv/src/unix/ev/ev.c index a3bec43fbe..b6e190f75f 100644 --- a/deps/uv/src/unix/ev/ev.c +++ b/deps/uv/src/unix/ev/ev.c @@ -1958,6 +1958,12 @@ ev_loop_new (unsigned int flags) #endif /* multiplicity */ +int +ev_loop_refcount (EV_P) +{ + return activecnt; +} + #if EV_VERIFY static void noinline verify_watcher (EV_P_ W w) diff --git a/deps/uv/src/unix/udp.c b/deps/uv/src/unix/udp.c index cbb37669a2..6760c3108d 100644 --- a/deps/uv/src/unix/udp.c +++ b/deps/uv/src/unix/udp.c @@ -42,6 +42,10 @@ static int uv__udp_send(uv_udp_send_t* req, uv_udp_t* handle, uv_buf_t bufs[], static void uv__udp_watcher_start(uv_udp_t* handle, ev_io* w) { int flags; + if (ev_is_active(w)) { + return; + } + assert(w == &handle->read_watcher || w == &handle->write_watcher); @@ -51,17 +55,23 @@ static void uv__udp_watcher_start(uv_udp_t* handle, ev_io* w) { ev_set_cb(w, uv__udp_io); ev_io_set(w, handle->fd, flags); ev_io_start(handle->loop->ev, w); + ev_unref(handle->loop->ev); } void uv__udp_watcher_stop(uv_udp_t* handle, ev_io* w) { int flags; + if (!ev_is_active(w)) { + return; + } + assert(w == &handle->read_watcher || w == &handle->write_watcher); flags = (w == &handle->read_watcher ? EV_READ : EV_WRITE); + ev_ref(handle->loop->ev); ev_io_stop(handle->loop->ev, w); ev_io_set(w, -1, flags); ev_set_cb(w, NULL); @@ -332,7 +342,7 @@ static int uv__bind(uv_udp_t* handle, goto out; } #else - uv__set_sys_error((uv_handle_t*)handle, ENOTSUP); + uv__set_sys_error(handle->loop, ENOTSUP); goto out; #endif } diff --git a/deps/uv/src/win/core.c b/deps/uv/src/win/core.c index 5f61f0ab9e..70da4273bd 100644 --- a/deps/uv/src/win/core.c +++ b/deps/uv/src/win/core.c @@ -116,6 +116,11 @@ void uv_loop_delete(uv_loop_t* loop) { } +int uv_loop_refcount(const uv_loop_t* loop) { + return loop->refs; +} + + void uv_ref(uv_loop_t* loop) { loop->refs++; } diff --git a/deps/uv/src/win/fs.c b/deps/uv/src/win/fs.c index 78ccffab6b..d7087b1f55 100644 --- a/deps/uv/src/win/fs.c +++ b/deps/uv/src/win/fs.c @@ -490,38 +490,69 @@ void fs__readdir(uv_fs_t* req, const wchar_t* path, int flags) { void fs__stat(uv_fs_t* req, const wchar_t* path) { + HANDLE file; + WIN32_FIND_DATAW ent; int result; - unsigned short mode; - fs__open(req, path, _O_RDONLY, 0); - if (req->result == -1) { + req->ptr = NULL; + + file = FindFirstFileExW(path, FindExInfoStandard, &ent, + FindExSearchNameMatch, NULL, 0); + + if (file == INVALID_HANDLE_VALUE) { + SET_REQ_RESULT_WIN32_ERROR(req, GetLastError()); return; } - result = _fstati64(req->result, &req->stat); - if (result == -1) { - req->ptr = NULL; - } else { + FindClose(file); - /* - * VC CRT doesn't properly set S_IFDIR in _fstati64, - * so we set it here if path is a directory. - */ - if (GetFileAttributesW(path) & FILE_ATTRIBUTE_DIRECTORY) { - mode = req->stat.st_mode; - mode &= ~_S_IFMT; - mode |= _S_IFDIR; - - req->stat.st_mode = mode; - assert((req->stat.st_mode & _S_IFMT) == _S_IFDIR); + if (ent.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT && + ent.dwReserved0 == IO_REPARSE_TAG_SYMLINK) { + fs__open(req, path, _O_RDONLY, 0); + if (req->result != -1) { + result = _fstati64(req->result, &req->stat); + _close(req->result); + + if (result != -1) { + req->ptr = &req->stat; + } + + SET_REQ_RESULT(req, result); } - req->ptr = &req->stat; + return; } - _close(req->result); + req->stat.st_ino = 0; + req->stat.st_uid = 0; + req->stat.st_gid = 0; + req->stat.st_mode = 0; + req->stat.st_rdev = 0; + req->stat.st_dev = 0; + req->stat.st_nlink = 1; - SET_REQ_RESULT(req, result); + if (ent.dwFileAttributes & FILE_ATTRIBUTE_READONLY ) { + req->stat.st_mode |= (_S_IREAD + (_S_IREAD >> 3) + (_S_IREAD >> 6)); + } else { + req->stat.st_mode |= ((_S_IREAD|_S_IWRITE) + ((_S_IREAD|_S_IWRITE) >> 3) + + ((_S_IREAD|_S_IWRITE) >> 6)); + } + + if (ent.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { + req->stat.st_mode |= _S_IFDIR; + } else { + req->stat.st_mode |= _S_IFREG; + } + + uv_filetime_to_time_t(&ent.ftLastWriteTime, &(req->stat.st_mtime)); + uv_filetime_to_time_t(&ent.ftLastAccessTime, &(req->stat.st_atime)); + uv_filetime_to_time_t(&ent.ftCreationTime, &(req->stat.st_ctime)); + + req->stat.st_size = ((int64_t)ent.nFileSizeHigh << 32) + + (int64_t)ent.nFileSizeLow; + + req->ptr = &req->stat; + req->result = 0; } @@ -1543,3 +1574,4 @@ void uv_fs_req_cleanup(uv_fs_t* req) { req->flags |= UV_FS_CLEANEDUP; } + diff --git a/deps/uv/src/win/internal.h b/deps/uv/src/win/internal.h index e7d6c974bf..0dc551dbaa 100644 --- a/deps/uv/src/win/internal.h +++ b/deps/uv/src/win/internal.h @@ -284,10 +284,8 @@ void uv_fs_event_endgame(uv_loop_t* loop, uv_fs_event_t* handle); /* Utils */ int uv_parent_pid(); - - +void uv_filetime_to_time_t(FILETIME* file_time, time_t* stat_time); void uv_fatal_error(const int errorno, const char* syscall); - uv_err_code uv_translate_sys_error(int sys_errno); #define SET_REQ_STATUS(req, status) \ diff --git a/deps/uv/src/win/util.c b/deps/uv/src/win/util.c index 6b508e4a0d..f50952b91b 100644 --- a/deps/uv/src/win/util.c +++ b/deps/uv/src/win/util.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "uv.h" #include "internal.h" @@ -579,3 +580,25 @@ void uv_free_interface_addresses(uv_interface_address_t* addresses, free(addresses); } + + +void uv_filetime_to_time_t(FILETIME* file_time, time_t* stat_time) { + FILETIME local_time; + SYSTEMTIME system_time; + struct tm time; + + if ((file_time->dwLowDateTime || file_time->dwHighDateTime) && + FileTimeToLocalFileTime(file_time, &local_time) && + FileTimeToSystemTime(&local_time, &system_time)) { + time.tm_year = system_time.wYear - 1900; + time.tm_mon = system_time.wMonth - 1; + time.tm_mday = system_time.wDay; + time.tm_hour = system_time.wHour; + time.tm_min = system_time.wMinute; + time.tm_sec = system_time.wSecond; + + *stat_time = mktime(&time); + } else { + *stat_time = 0; + } +} diff --git a/deps/uv/test/echo-server.c b/deps/uv/test/echo-server.c index 8b1754410c..6b0d897214 100644 --- a/deps/uv/test/echo-server.c +++ b/deps/uv/test/echo-server.c @@ -34,6 +34,7 @@ static uv_loop_t* loop; static int server_closed; static stream_type serverType; static uv_tcp_t tcpServer; +static uv_udp_t udpServer; static uv_pipe_t pipeServer; static uv_handle_t* server; @@ -176,6 +177,34 @@ static void on_server_close(uv_handle_t* handle) { } +static void on_send(uv_udp_send_t* req, int status); + + +static void on_recv(uv_udp_t* handle, + ssize_t nread, + uv_buf_t buf, + struct sockaddr* addr, + unsigned flags) { + uv_udp_send_t* req; + int r; + + ASSERT(nread > 0); + ASSERT(addr->sa_family == AF_INET); + + req = malloc(sizeof(*req)); + ASSERT(req != NULL); + + r = uv_udp_send(req, handle, &buf, 1, *(struct sockaddr_in*)addr, on_send); + ASSERT(r == 0); +} + + +static void on_send(uv_udp_send_t* req, int status) { + ASSERT(status == 0); + free(req); +} + + static int tcp4_echo_start(int port) { struct sockaddr_in addr = uv_ip4_addr("0.0.0.0", port); int r; @@ -242,6 +271,30 @@ static int tcp6_echo_start(int port) { } +static int udp4_echo_start(int port) { + int r; + + server = (uv_handle_t*)&udpServer; + serverType = UDP; + + r = uv_udp_init(loop, &udpServer); + if (r) { + fprintf(stderr, "uv_udp_init: %s\n", + uv_strerror(uv_last_error(loop))); + return 1; + } + + r = uv_udp_recv_start(&udpServer, echo_alloc, on_recv); + if (r) { + fprintf(stderr, "uv_udp_recv_start: %s\n", + uv_strerror(uv_last_error(loop))); + return 1; + } + + return 0; +} + + static int pipe_echo_start(char* pipeName) { int r; @@ -304,3 +357,14 @@ HELPER_IMPL(pipe_echo_server) { uv_run(loop); return 0; } + + +HELPER_IMPL(udp4_echo_server) { + loop = uv_default_loop(); + + if (udp4_echo_start(TEST_PORT)) + return 1; + + uv_run(loop); + return 0; +} diff --git a/deps/uv/test/task.h b/deps/uv/test/task.h index e28b393bb7..b553f862fc 100644 --- a/deps/uv/test/task.h +++ b/deps/uv/test/task.h @@ -42,6 +42,7 @@ typedef enum { TCP = 0, + UDP, PIPE } stream_type; diff --git a/deps/uv/test/test-eio-overflow.c b/deps/uv/test/test-eio-overflow.c index 51720f1748..de3d65b754 100644 --- a/deps/uv/test/test-eio-overflow.c +++ b/deps/uv/test/test-eio-overflow.c @@ -46,9 +46,11 @@ void after_work_cb(uv_work_t* work) { void make_eio_req(void) { + uv_work_t* w; + opened++; - uv_work_t* w = (uv_work_t*) malloc(sizeof(*w)); + w = (uv_work_t*) malloc(sizeof(*w)); ASSERT(w != NULL); uv_queue_work(uv_default_loop(), w, work_cb, after_work_cb); diff --git a/deps/uv/test/test-fs-event.c b/deps/uv/test/test-fs-event.c index 97d91ee3ec..871d0e7d2e 100644 --- a/deps/uv/test/test-fs-event.c +++ b/deps/uv/test/test-fs-event.c @@ -328,21 +328,3 @@ TEST_IMPL(fs_event_immediate_close) { return 0; } - - -TEST_IMPL(fs_event_unref) { - uv_loop_t* loop; - int r; - - loop = uv_default_loop(); - - r = uv_fs_event_init(loop, &fs_event, ".", fs_event_fail, 0); - ASSERT(r == 0); - - uv_unref(loop); - - r = uv_run(loop); - ASSERT(r == 0); - - return 0; -} diff --git a/deps/uv/test/test-list.h b/deps/uv/test/test-list.h index 339d186dc7..0678372ae4 100644 --- a/deps/uv/test/test-list.h +++ b/deps/uv/test/test-list.h @@ -26,8 +26,6 @@ TEST_DECLARE (ipc_listen_before_write) TEST_DECLARE (ipc_listen_after_write) TEST_DECLARE (tcp_ping_pong) TEST_DECLARE (tcp_ping_pong_v6) -TEST_DECLARE (tcp_ref) -TEST_DECLARE (tcp_ref2) TEST_DECLARE (pipe_ping_pong) TEST_DECLARE (delayed_accept) TEST_DECLARE (multiple_listen) @@ -64,18 +62,29 @@ TEST_DECLARE (shutdown_eof) TEST_DECLARE (callback_stack) TEST_DECLARE (error_message) TEST_DECLARE (timer) -TEST_DECLARE (timer_ref) -TEST_DECLARE (timer_ref2) TEST_DECLARE (timer_again) TEST_DECLARE (idle_starvation) TEST_DECLARE (loop_handles) +TEST_DECLARE (get_loadavg) TEST_DECLARE (ref) TEST_DECLARE (idle_ref) -TEST_DECLARE (get_loadavg) TEST_DECLARE (async_ref) TEST_DECLARE (prepare_ref) TEST_DECLARE (check_ref) TEST_DECLARE (unref_in_prepare_cb) +TEST_DECLARE (timer_ref) +TEST_DECLARE (timer_ref2) +TEST_DECLARE (fs_event_ref) +TEST_DECLARE (tcp_ref) +TEST_DECLARE (tcp_ref2) +TEST_DECLARE (tcp_ref3) +TEST_DECLARE (udp_ref) +TEST_DECLARE (udp_ref2) +TEST_DECLARE (udp_ref3) +TEST_DECLARE (pipe_ref) +TEST_DECLARE (pipe_ref2) +TEST_DECLARE (pipe_ref3) +TEST_DECLARE (process_ref) TEST_DECLARE (async) TEST_DECLARE (get_currentexe) TEST_DECLARE (process_title) @@ -115,7 +124,6 @@ TEST_DECLARE (fs_event_watch_file) TEST_DECLARE (fs_event_watch_file_current_dir) TEST_DECLARE (fs_event_no_callback_on_close) TEST_DECLARE (fs_event_immediate_close) -TEST_DECLARE (fs_event_unref) TEST_DECLARE (fs_readdir_empty_dir) TEST_DECLARE (fs_readdir_file) TEST_DECLARE (fs_open_dir) @@ -138,6 +146,7 @@ TEST_DECLARE (listen_no_simultaneous_accepts) #endif HELPER_DECLARE (tcp4_echo_server) HELPER_DECLARE (tcp6_echo_server) +HELPER_DECLARE (udp4_echo_server) HELPER_DECLARE (pipe_echo_server) @@ -151,11 +160,6 @@ TASK_LIST_START TEST_ENTRY (ipc_listen_before_write) TEST_ENTRY (ipc_listen_after_write) - TEST_ENTRY (tcp_ref) - - TEST_ENTRY (tcp_ref2) - TEST_HELPER (tcp_ref2, tcp4_echo_server) - TEST_ENTRY (tcp_ping_pong) TEST_HELPER (tcp_ping_pong, tcp4_echo_server) @@ -212,9 +216,6 @@ TASK_LIST_START TEST_ENTRY (error_message) TEST_ENTRY (timer) - TEST_ENTRY (timer_ref) - TEST_ENTRY (timer_ref2) - TEST_ENTRY (timer_again) TEST_ENTRY (idle_starvation) @@ -225,6 +226,22 @@ TASK_LIST_START TEST_ENTRY (prepare_ref) TEST_ENTRY (check_ref) TEST_ENTRY (unref_in_prepare_cb) + TEST_ENTRY (timer_ref) + TEST_ENTRY (timer_ref2) + TEST_ENTRY (fs_event_ref) + TEST_ENTRY (tcp_ref) + TEST_ENTRY (tcp_ref2) + TEST_ENTRY (tcp_ref3) + TEST_HELPER (tcp_ref3, tcp4_echo_server) + TEST_ENTRY (udp_ref) + TEST_ENTRY (udp_ref2) + TEST_ENTRY (udp_ref3) + TEST_HELPER (udp_ref3, udp4_echo_server) + TEST_ENTRY (pipe_ref) + TEST_ENTRY (pipe_ref2) + TEST_ENTRY (pipe_ref3) + TEST_HELPER (pipe_ref3, pipe_echo_server) + TEST_ENTRY (process_ref) TEST_ENTRY (loop_handles) @@ -284,7 +301,6 @@ TASK_LIST_START TEST_ENTRY (fs_event_watch_file_current_dir) TEST_ENTRY (fs_event_no_callback_on_close) TEST_ENTRY (fs_event_immediate_close) - TEST_ENTRY (fs_event_unref) TEST_ENTRY (fs_readdir_empty_dir) TEST_ENTRY (fs_readdir_file) TEST_ENTRY (fs_open_dir) diff --git a/deps/uv/test/test-ref.c b/deps/uv/test/test-ref.c index 0083335fd1..2b8aabbc6f 100644 --- a/deps/uv/test/test-ref.c +++ b/deps/uv/test/test-ref.c @@ -22,6 +22,14 @@ #include "uv.h" #include "task.h" +#include +#include + + +static void fail_cb(void) { + FATAL("fail_cb should not have been called"); +} + TEST_IMPL(ref) { uv_run(uv_default_loop()); @@ -83,3 +91,164 @@ TEST_IMPL(unref_in_prepare_cb) { uv_run(uv_default_loop()); return 0; } + + +TEST_IMPL(timer_ref) { + uv_timer_t h; + uv_timer_init(uv_default_loop(), &h); + uv_unref(uv_default_loop()); + uv_run(uv_default_loop()); + return 0; +} + + +TEST_IMPL(timer_ref2) { + uv_timer_t h; + uv_timer_init(uv_default_loop(), &h); + uv_timer_start(&h, (uv_timer_cb) fail_cb, 42, 42); + uv_unref(uv_default_loop()); + uv_run(uv_default_loop()); + return 0; +} + + +TEST_IMPL(fs_event_ref) { + uv_fs_event_t h; + uv_fs_event_init(uv_default_loop(), &h, ".", (uv_fs_event_cb) fail_cb, 0); + uv_unref(uv_default_loop()); + uv_run(uv_default_loop()); + return 0; +} + + +TEST_IMPL(tcp_ref) { + uv_tcp_t h; + uv_tcp_init(uv_default_loop(), &h); + uv_unref(uv_default_loop()); + uv_run(uv_default_loop()); + return 0; +} + + +TEST_IMPL(tcp_ref2) { + uv_tcp_t h; + uv_tcp_init(uv_default_loop(), &h); + uv_listen((uv_stream_t*)&h, 128, (uv_connection_cb)fail_cb); + uv_unref(uv_default_loop()); + uv_run(uv_default_loop()); + return 0; +} + + +TEST_IMPL(tcp_ref3) { + struct sockaddr_in addr = uv_ip4_addr("127.0.0.1", TEST_PORT); + uv_connect_t req; + uv_tcp_t h; + uv_tcp_init(uv_default_loop(), &h); + uv_tcp_connect(&req, &h, addr, (uv_connect_cb)fail_cb); + uv_unref(uv_default_loop()); + uv_unref(uv_default_loop()); /* connect req refs the loop */ + uv_run(uv_default_loop()); + return 0; +} + + +TEST_IMPL(udp_ref) { + uv_udp_t h; + uv_udp_init(uv_default_loop(), &h); + uv_unref(uv_default_loop()); + uv_run(uv_default_loop()); + return 0; +} + + +TEST_IMPL(udp_ref2) { + struct sockaddr_in addr = uv_ip4_addr("127.0.0.1", TEST_PORT); + uv_udp_t h; + uv_udp_init(uv_default_loop(), &h); + uv_udp_bind(&h, addr, 0); + uv_udp_recv_start(&h, (uv_alloc_cb)fail_cb, (uv_udp_recv_cb)fail_cb); + uv_unref(uv_default_loop()); + uv_run(uv_default_loop()); + return 0; +} + + +TEST_IMPL(udp_ref3) { + struct sockaddr_in addr = uv_ip4_addr("127.0.0.1", TEST_PORT); + uv_buf_t buf = uv_buf_init("PING", 4); + uv_udp_send_t req; + uv_udp_t h; + + uv_udp_init(uv_default_loop(), &h); + uv_udp_send(&req, &h, &buf, 1, addr, (uv_udp_send_cb)fail_cb); + uv_unref(uv_default_loop()); + uv_unref(uv_default_loop()); /* send req refs the loop */ + uv_run(uv_default_loop()); + + return 0; +} + + +TEST_IMPL(pipe_ref) { + uv_pipe_t h; + uv_pipe_init(uv_default_loop(), &h, 0); + uv_unref(uv_default_loop()); + uv_run(uv_default_loop()); + return 0; +} + + +TEST_IMPL(pipe_ref2) { + uv_pipe_t h; + uv_pipe_init(uv_default_loop(), &h, 0); + uv_listen((uv_stream_t*)&h, 128, (uv_connection_cb)fail_cb); + uv_unref(uv_default_loop()); + uv_run(uv_default_loop()); + return 0; +} + + +TEST_IMPL(pipe_ref3) { + uv_connect_t req; + uv_pipe_t h; + uv_pipe_init(uv_default_loop(), &h, 0); + uv_pipe_connect(&req, &h, TEST_PIPENAME, (uv_connect_cb)fail_cb); + uv_unref(uv_default_loop()); + uv_unref(uv_default_loop()); /* connect req refs the loop */ + uv_run(uv_default_loop()); + return 0; +} + + +TEST_IMPL(process_ref) { + /* spawn_helper4 blocks indefinitely. */ + char *argv[] = { NULL, "spawn_helper4", NULL }; + uv_process_options_t options; + size_t exepath_size; + char exepath[256]; + uv_process_t h; + int r; + + memset(&options, 0, sizeof(options)); + exepath_size = sizeof(exepath); + + r = uv_exepath(exepath, &exepath_size); + ASSERT(r == 0); + + argv[0] = exepath; + options.file = exepath; + options.args = argv; + options.exit_cb = NULL; + + r = uv_spawn(uv_default_loop(), &h, options); + ASSERT(r == 0); + + uv_unref(uv_default_loop()); + uv_run(uv_default_loop()); + + r = uv_process_kill(&h, /* SIGTERM */ 15); + ASSERT(r == 0); + + return 0; +} diff --git a/deps/uv/test/test-tcp-close.c b/deps/uv/test/test-tcp-close.c index f5dd0a4405..5da8a84f8a 100644 --- a/deps/uv/test/test-tcp-close.c +++ b/deps/uv/test/test-tcp-close.c @@ -127,50 +127,3 @@ TEST_IMPL(tcp_close) { return 0; } - - -TEST_IMPL(tcp_ref) { - uv_tcp_t never; - int r; - - /* A tcp just initialized should count as one reference. */ - r = uv_tcp_init(uv_default_loop(), &never); - ASSERT(r == 0); - - /* One unref should set the loop ref count to zero. */ - uv_unref(uv_default_loop()); - - /* Therefore this does not block */ - uv_run(uv_default_loop()); - - return 0; -} - - -static void never_cb(uv_connect_t* conn_req, int status) { - FATAL("never_cb should never be called"); -} - - -TEST_IMPL(tcp_ref2) { - uv_tcp_t never; - int r; - - /* A tcp just initialized should count as one reference. */ - r = uv_tcp_init(uv_default_loop(), &never); - ASSERT(r == 0); - - r = uv_tcp_connect(&connect_req, - &never, - uv_ip4_addr("127.0.0.1", TEST_PORT), - never_cb); - ASSERT(r == 0); - - /* One unref should set the loop ref count to zero. */ - uv_unref(uv_default_loop()); - - /* Therefore this does not block */ - uv_run(uv_default_loop()); - - return 0; -} diff --git a/deps/uv/test/test-timer.c b/deps/uv/test/test-timer.c index 87235a51bc..17bcb84b77 100644 --- a/deps/uv/test/test-timer.c +++ b/deps/uv/test/test-timer.c @@ -130,43 +130,3 @@ TEST_IMPL(timer) { return 0; } - - -TEST_IMPL(timer_ref) { - uv_timer_t never; - int r; - - /* A timer just initialized should count as one reference. */ - r = uv_timer_init(uv_default_loop(), &never); - ASSERT(r == 0); - - /* One unref should set the loop ref count to zero. */ - uv_unref(uv_default_loop()); - - /* Therefore this does not block */ - uv_run(uv_default_loop()); - - return 0; -} - - -TEST_IMPL(timer_ref2) { - uv_timer_t never; - int r; - - /* A timer just initialized should count as one reference. */ - r = uv_timer_init(uv_default_loop(), &never); - ASSERT(r == 0); - - /* We start the timer, this should not effect the ref count. */ - r = uv_timer_start(&never, never_cb, 1000, 1000); - ASSERT(r == 0); - - /* One unref should set the loop ref count to zero. */ - uv_unref(uv_default_loop()); - - /* Therefore this does not block */ - uv_run(uv_default_loop()); - - return 0; -}