From 76fd364dfee514c4081fc63cf6c962fce3839113 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Mon, 1 Aug 2011 14:49:58 -0700 Subject: [PATCH] Upgrade libuv to 5af7423f --- deps/uv/src/uv-unix.c | 63 ++++++++++++++++++++++----------------- deps/uv/src/win/process.c | 46 ++++++++++++---------------- deps/uv/test/run-tests.c | 56 ++++++++++++++++++---------------- 3 files changed, 85 insertions(+), 80 deletions(-) diff --git a/deps/uv/src/uv-unix.c b/deps/uv/src/uv-unix.c index eb5f4cbadda..c7cca6f8e11 100644 --- a/deps/uv/src/uv-unix.c +++ b/deps/uv/src/uv-unix.c @@ -42,6 +42,7 @@ #include #include #include /* PATH_MAX */ +#include /* writev */ #ifdef __sun # include @@ -108,7 +109,7 @@ int uv_flock_destroy(uv_flock_t* lock); void uv__req_init(uv_req_t*); void uv__next(EV_P_ ev_idle* watcher, int revents); -static int uv__stream_open(uv_stream_t*, int fd); +static int uv__stream_open(uv_stream_t*, int fd, int flags); static void uv__finish_close(uv_handle_t* handle); static uv_err_t uv_err_new(uv_handle_t* handle, int sys_error); @@ -142,7 +143,9 @@ enum { UV_CLOSED = 0x00000002, /* close(2) finished. */ UV_READING = 0x00000004, /* uv_read_start() called. */ UV_SHUTTING = 0x00000008, /* uv_shutdown() called but not complete. */ - UV_SHUT = 0x00000010 /* Write side closed. */ + UV_SHUT = 0x00000010, /* Write side closed. */ + UV_READABLE = 0x00000020, /* The stream is readable */ + UV_WRITABLE = 0x00000040 /* The stream is writable */ }; @@ -369,7 +372,7 @@ static int uv__bind(uv_tcp_t* tcp, int domain, struct sockaddr* addr, goto out; } - if (uv__stream_open((uv_stream_t*)tcp, fd)) { + if (uv__stream_open((uv_stream_t*)tcp, fd, UV_READABLE | UV_WRITABLE)) { status = -2; uv__close(fd); goto out; @@ -417,12 +420,14 @@ int uv_tcp_bind6(uv_tcp_t* tcp, struct sockaddr_in6 addr) { } -static int uv__stream_open(uv_stream_t* stream, int fd) { +static int uv__stream_open(uv_stream_t* stream, int fd, int flags) { socklen_t yes; assert(fd >= 0); stream->fd = fd; + uv_flag_set((uv_handle_t*)stream, flags); + /* Reuse the port address if applicable. */ yes = 1; if (stream->type == UV_TCP @@ -505,7 +510,8 @@ int uv_accept(uv_stream_t* server, uv_stream_t* client) { goto out; } - if (uv__stream_open(streamClient, streamServer->accepted_fd)) { + if (uv__stream_open(streamClient, streamServer->accepted_fd, + UV_READABLE | UV_WRITABLE)) { /* TODO handle error */ streamServer->accepted_fd = -1; uv__close(streamServer->accepted_fd); @@ -550,7 +556,7 @@ static int uv_tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb) { return -1; } - if (uv__stream_open((uv_stream_t*)tcp, fd)) { + if (uv__stream_open((uv_stream_t*)tcp, fd, UV_READABLE)) { uv__close(fd); return -1; } @@ -898,29 +904,30 @@ static void uv__read(uv_stream_t* stream) { } -int uv_shutdown(uv_shutdown_t* req, uv_stream_t* handle, uv_shutdown_cb cb) { - uv_tcp_t* tcp = (uv_tcp_t*)handle; - assert((handle->type == UV_TCP || handle->type == UV_NAMED_PIPE) - && "uv_shutdown (unix) only supports uv_tcp_t right now"); - assert(tcp->fd >= 0); +int uv_shutdown(uv_shutdown_t* req, uv_stream_t* stream, uv_shutdown_cb cb) { + assert((stream->type == UV_TCP || stream->type == UV_NAMED_PIPE) && + "uv_shutdown (unix) only supports uv_handle_t right now"); + assert(stream->fd >= 0); - /* Initialize request */ - uv__req_init((uv_req_t*)req); - req->handle = handle; - req->cb = cb; - - if (uv_flag_is_set((uv_handle_t*)tcp, UV_SHUT) || - uv_flag_is_set((uv_handle_t*)tcp, UV_CLOSED) || - uv_flag_is_set((uv_handle_t*)tcp, UV_CLOSING)) { + if (!uv_flag_is_set((uv_handle_t*)stream, UV_WRITABLE) || + uv_flag_is_set((uv_handle_t*)stream, UV_SHUT) || + uv_flag_is_set((uv_handle_t*)stream, UV_CLOSED) || + uv_flag_is_set((uv_handle_t*)stream, UV_CLOSING)) { + uv_err_new((uv_handle_t*)stream, EINVAL); return -1; } - tcp->shutdown_req = req; + /* Initialize request */ + uv__req_init((uv_req_t*)req); + req->handle = stream; + req->cb = cb; + + stream->shutdown_req = req; req->type = UV_SHUTDOWN; - uv_flag_set((uv_handle_t*)tcp, UV_SHUTTING); + uv_flag_set((uv_handle_t*)stream, UV_SHUTTING); - ev_io_start(EV_DEFAULT_UC_ &tcp->write_watcher); + ev_io_start(EV_DEFAULT_UC_ &stream->write_watcher); return 0; } @@ -1029,7 +1036,7 @@ static int uv__connect(uv_connect_t* req, return -1; } - if (uv__stream_open(stream, sockfd)) { + if (uv__stream_open(stream, sockfd, UV_READABLE | UV_WRITABLE)) { uv__close(sockfd); return -2; } @@ -1924,7 +1931,6 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) { /* Success. */ handle->pipe_fname = pipe_fname; /* Is a strdup'ed copy. */ - handle->pipe_flock = pipe_flock; handle->fd = sockfd; status = 0; @@ -2357,7 +2363,8 @@ int uv_spawn(uv_process_t* process, uv_process_options_t options) { assert(stdin_pipe[0] >= 0); uv__close(stdin_pipe[0]); uv__nonblock(stdin_pipe[1], 1); - uv__stream_open((uv_stream_t*)options.stdin_stream, stdin_pipe[1]); + uv__stream_open((uv_stream_t*)options.stdin_stream, stdin_pipe[1], + UV_WRITABLE); } if (stdout_pipe[0] >= 0) { @@ -2365,7 +2372,8 @@ int uv_spawn(uv_process_t* process, uv_process_options_t options) { assert(stdout_pipe[1] >= 0); uv__close(stdout_pipe[1]); uv__nonblock(stdout_pipe[0], 1); - uv__stream_open((uv_stream_t*)options.stdout_stream, stdout_pipe[0]); + uv__stream_open((uv_stream_t*)options.stdout_stream, stdout_pipe[0], + UV_READABLE); } if (stderr_pipe[0] >= 0) { @@ -2373,7 +2381,8 @@ int uv_spawn(uv_process_t* process, uv_process_options_t options) { assert(stderr_pipe[1] >= 0); uv__close(stderr_pipe[1]); uv__nonblock(stderr_pipe[0], 1); - uv__stream_open((uv_stream_t*)options.stderr_stream, stderr_pipe[0]); + uv__stream_open((uv_stream_t*)options.stderr_stream, stderr_pipe[0], + UV_READABLE); } return 0; diff --git a/deps/uv/src/win/process.c b/deps/uv/src/win/process.c index f2943f81a01..e259677af9b 100644 --- a/deps/uv/src/win/process.c +++ b/deps/uv/src/win/process.c @@ -41,8 +41,7 @@ } -static const wchar_t DEFAULT_PATH[1] = L""; -static const wchar_t DEFAULT_PATH_EXT[20] = L".COM;.EXE;.BAT;.CMD"; +static const wchar_t DEFAULT_PATH_EXT[10] = L".COM;.EXE"; static void uv_process_init(uv_process_t* handle) { @@ -408,10 +407,8 @@ static wchar_t* make_program_args(char** args) { * The way windows takes environment variables is different than what C does; * Windows wants a contiguous block of null-terminated strings, terminated * with an additional null. - * Get a pointer to the pathext and path environment variables as well, - * because search_path needs it. These are just pointers into env_win. */ -wchar_t* make_program_env(char** env_block, const wchar_t **path, const wchar_t **path_ext) { +wchar_t* make_program_env(char** env_block) { wchar_t* dst; wchar_t* ptr; char** env; @@ -435,14 +432,6 @@ wchar_t* make_program_env(char** env_block, const wchar_t **path, const wchar_t free(dst); return NULL; } - - /* Try to get a pointer to PATH and PATHEXT */ - if (_wcsnicmp(L"PATH=", ptr, 5) == 0) { - *path = ptr + 5; - } - if (_wcsnicmp(L"PATHEXT=", ptr, 8) == 0) { - *path_ext = ptr + 8; - } } *ptr = L'\0'; @@ -636,8 +625,7 @@ done: int uv_spawn(uv_process_t* process, uv_process_options_t options) { int err, i; - const wchar_t* path = NULL; - const wchar_t* path_ext = NULL; + wchar_t* path; int size; wchar_t* application_path, *application, *arguments, *env, *cwd; STARTUPINFOW startup; @@ -648,7 +636,7 @@ int uv_spawn(uv_process_t* process, uv_process_options_t options) { process->exit_cb = options.exit_cb; UTF8_TO_UTF16(options.file, application); arguments = options.args ? make_program_args(options.args) : NULL; - env = options.env ? make_program_env(options.env, &path, &path_ext) : NULL; + env = options.env ? make_program_env(options.env) : NULL; if (options.cwd) { UTF8_TO_UTF16(options.cwd, cwd); @@ -667,10 +655,19 @@ int uv_spawn(uv_process_t* process, uv_process_options_t options) { } } + /* Get PATH env. variable. */ + size = GetEnvironmentVariableW(L"PATH", NULL, 0) + 1; + path = (wchar_t*)malloc(size * sizeof(wchar_t)); + if (!path) { + uv_fatal_error(ERROR_OUTOFMEMORY, "malloc"); + } + GetEnvironmentVariableW(L"PATH", path, size * sizeof(wchar_t)); + path[size - 1] = L'\0'; + application_path = search_path(application, cwd, - path ? path : DEFAULT_PATH, - path_ext ? path_ext : DEFAULT_PATH_EXT); + path, + DEFAULT_PATH_EXT); if (!application_path) { uv_set_error(UV_EINVAL, 0); @@ -680,9 +677,7 @@ int uv_spawn(uv_process_t* process, uv_process_options_t options) { /* Create stdio pipes. */ if (options.stdin_stream) { - err = uv_create_stdio_pipe_pair(options.stdin_stream, - &process->stdio_pipes[0].child_pipe, PIPE_ACCESS_OUTBOUND, - GENERIC_READ | FILE_WRITE_ATTRIBUTES); + err = uv_create_stdio_pipe_pair(options.stdin_stream, &process->stdio_pipes[0].child_pipe, PIPE_ACCESS_OUTBOUND, GENERIC_READ | FILE_WRITE_ATTRIBUTES); if (err) { goto done; } @@ -691,9 +686,7 @@ int uv_spawn(uv_process_t* process, uv_process_options_t options) { } if (options.stdout_stream) { - err = uv_create_stdio_pipe_pair(options.stdout_stream, - &process->stdio_pipes[1].child_pipe, PIPE_ACCESS_INBOUND, - GENERIC_WRITE); + err = uv_create_stdio_pipe_pair(options.stdout_stream, &process->stdio_pipes[1].child_pipe, PIPE_ACCESS_INBOUND, GENERIC_WRITE); if (err) { goto done; } @@ -702,9 +695,7 @@ int uv_spawn(uv_process_t* process, uv_process_options_t options) { } if (options.stderr_stream) { - err = uv_create_stdio_pipe_pair(options.stderr_stream, - &process->stdio_pipes[2].child_pipe, PIPE_ACCESS_INBOUND, - GENERIC_WRITE); + err = uv_create_stdio_pipe_pair(options.stderr_stream, &process->stdio_pipes[2].child_pipe, PIPE_ACCESS_INBOUND, GENERIC_WRITE); if (err) { goto done; } @@ -759,6 +750,7 @@ done: free(arguments); free(cwd); free(env); + free(path); if (err) { for (i = 0; i < COUNTOF(process->stdio_pipes); i++) { diff --git a/deps/uv/test/run-tests.c b/deps/uv/test/run-tests.c index 8c80d34bed1..f7a868cb3a9 100644 --- a/deps/uv/test/run-tests.c +++ b/deps/uv/test/run-tests.c @@ -32,43 +32,47 @@ /* The time in milliseconds after which a single test times out. */ #define TEST_TIMEOUT 5000 +static int maybe_run_test(int argc, char **argv); + int main(int argc, char **argv) { int i; - char buffer[32]; platform_init(argc, argv); switch (argc) { case 1: return run_tests(TEST_TIMEOUT, 0); - case 2: { - if (strcmp(argv[1], "spawn_helper1") == 0) { - return 1; - } - - if (strcmp(argv[1], "spawn_helper2") == 0) { - printf("hello world\n"); - return 1; - } - - if (strcmp(argv[1], "spawn_helper3") == 0) { - fgets(buffer, sizeof(buffer) - 1, stdin); - buffer[sizeof(buffer) - 1] = '\0'; - fputs(buffer, stdout); - return 1; - } - - if (strcmp(argv[1], "spawn_helper4") == 0) { - // sleep - uv_sleep(10000); - return 100; - } - - return run_test(argv[1], TEST_TIMEOUT, 0); - } + case 2: return maybe_run_test(argc, argv); case 3: return run_test_part(argv[1], argv[2]); default: LOGF("Too many arguments.\n"); return 1; } } + + +static int maybe_run_test(int argc, char **argv) { + if (strcmp(argv[1], "spawn_helper1") == 0) { + return 1; + } + + if (strcmp(argv[1], "spawn_helper2") == 0) { + printf("hello world\n"); + return 1; + } + + if (strcmp(argv[1], "spawn_helper3") == 0) { + char buffer[256]; + fgets(buffer, sizeof(buffer) - 1, stdin); + buffer[sizeof(buffer) - 1] = '\0'; + fputs(buffer, stdout); + return 1; + } + + if (strcmp(argv[1], "spawn_helper4") == 0) { + uv_sleep(10000); + return 1; + } + + return run_test(argv[1], TEST_TIMEOUT, 0); +}