diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2012-01-03 18:15:54 +0400 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2012-01-06 03:00:40 +0400 |
commit | 075acfa2d6c823ec9ccedba5fdbca172752d1e4a (patch) | |
tree | 17d87f0c2a26dae8247b45959b281cdcf4103f46 /deps | |
parent | aa67b1f3750646a0f30e12a3b4e4fcb84dc8cafa (diff) |
uv: upgrade to 56a31f0
Diffstat (limited to 'deps')
-rw-r--r-- | deps/uv/include/uv.h | 10 | ||||
-rw-r--r-- | deps/uv/src/unix/dl.c | 22 | ||||
-rw-r--r-- | deps/uv/src/unix/internal.h | 5 | ||||
-rw-r--r-- | deps/uv/src/unix/pipe.c | 36 | ||||
-rw-r--r-- | deps/uv/src/unix/process.c | 7 | ||||
-rw-r--r-- | deps/uv/src/win/pipe.c | 6 | ||||
-rw-r--r-- | deps/uv/test/test-list.h | 3 | ||||
-rw-r--r-- | deps/uv/test/test-pipe-pair.c | 137 | ||||
-rw-r--r-- | deps/uv/uv.gyp | 1 |
9 files changed, 216 insertions, 11 deletions
diff --git a/deps/uv/include/uv.h b/deps/uv/include/uv.h index 7e089ef7243..4bfcb39fe87 100644 --- a/deps/uv/include/uv.h +++ b/deps/uv/include/uv.h @@ -785,6 +785,13 @@ struct uv_pipe_s { UV_EXTERN int uv_pipe_init(uv_loop_t*, uv_pipe_t* handle, int ipc); /* + * Connects two initialized pipes on different loops. + * Data written to one pipe will appear on the other side. + * This function is thread-safe. + */ +UV_EXTERN uv_err_t uv_pipe_pair(uv_pipe_t* a, uv_pipe_t* b); + +/* * Opens an existing file descriptor or HANDLE as a pipe. */ UV_EXTERN void uv_pipe_open(uv_pipe_t*, uv_file file); @@ -1313,7 +1320,8 @@ UV_EXTERN uv_err_t uv_dlopen(const char* filename, uv_lib_t* library); UV_EXTERN uv_err_t uv_dlclose(uv_lib_t library); /* - * Retrieves a data pointer from a dynamic library. + * Retrieves a data pointer from a dynamic library. It is legal for a symbol to + * map to NULL. */ UV_EXTERN uv_err_t uv_dlsym(uv_lib_t library, const char* name, void** ptr); diff --git a/deps/uv/src/unix/dl.c b/deps/uv/src/unix/dl.c index 6c4ddff89e6..41c244d79ea 100644 --- a/deps/uv/src/unix/dl.c +++ b/deps/uv/src/unix/dl.c @@ -25,11 +25,17 @@ #include <dlfcn.h> #include <errno.h> +/* The dl family of functions don't set errno. We need a good way to communicate + * errors to the caller but there is only dlerror() and that returns a string - + * a string that may or may not be safe to keep a reference to... + */ +static const uv_err_t uv_inval_ = { UV_EINVAL, EINVAL }; + uv_err_t uv_dlopen(const char* filename, uv_lib_t* library) { void* handle = dlopen(filename, RTLD_LAZY); if (handle == NULL) { - return uv__new_sys_error(errno); + return uv_inval_; } *library = handle; @@ -39,7 +45,7 @@ uv_err_t uv_dlopen(const char* filename, uv_lib_t* library) { uv_err_t uv_dlclose(uv_lib_t library) { if (dlclose(library) != 0) { - return uv__new_sys_error(errno); + return uv_inval_; } return uv_ok_; @@ -47,9 +53,15 @@ uv_err_t uv_dlclose(uv_lib_t library) { uv_err_t uv_dlsym(uv_lib_t library, const char* name, void** ptr) { - void* address = dlsym(library, name); - if (address == NULL) { - return uv__new_sys_error(errno); + void* address; + + /* Reset error status. */ + dlerror(); + + address = dlsym(library, name); + + if (dlerror()) { + return uv_inval_; } *ptr = (void*) address; diff --git a/deps/uv/src/unix/internal.h b/deps/uv/src/unix/internal.h index 17381f339f8..3a51fc89fea 100644 --- a/deps/uv/src/unix/internal.h +++ b/deps/uv/src/unix/internal.h @@ -185,4 +185,9 @@ void uv__udp_watcher_stop(uv_udp_t* handle, ev_io* w); /* fs */ void uv__fs_event_destroy(uv_fs_event_t* handle); +#define UV__F_IPC (1 << 0) +#define UV__F_NONBLOCK (1 << 1) +int uv__make_socketpair(int fds[2], int flags); +int uv__make_pipe(int fds[2], int flags); + #endif /* UV_UNIX_INTERNAL_H_ */ diff --git a/deps/uv/src/unix/pipe.c b/deps/uv/src/unix/pipe.c index de89961fb5a..8f2162ddd02 100644 --- a/deps/uv/src/unix/pipe.c +++ b/deps/uv/src/unix/pipe.c @@ -30,6 +30,10 @@ #include <stdlib.h> +static uv_once_t uv__pipe_pair_lock_guard = UV_ONCE_INIT; +static uv_mutex_t uv__pipe_pair_lock; + + int uv_pipe_init(uv_loop_t* loop, uv_pipe_t* handle, int ipc) { uv__stream_init(loop, (uv_stream_t*)handle, UV_NAMED_PIPE); loop->counters.pipe_init++; @@ -39,6 +43,38 @@ int uv_pipe_init(uv_loop_t* loop, uv_pipe_t* handle, int ipc) { } +void uv__pipe_pair_lock_init() { + uv_mutex_init(&uv__pipe_pair_lock); +} + + +uv_err_t uv_pipe_pair(uv_pipe_t* a, uv_pipe_t* b) { + int fds[2]; + int r; + uv_err_t err; + + /* Make sure that the mutex is only initialized once. */ + uv_once(&uv__pipe_pair_lock_guard, uv__pipe_pair_lock_init); + + uv_mutex_lock(&uv__pipe_pair_lock); + + r = uv__make_socketpair(fds, UV__F_NONBLOCK | UV__F_IPC); + + if (r) { + err = uv__new_sys_error(errno); + } else { + uv_pipe_open(a, fds[0]); + uv_pipe_open(b, fds[1]); + err = uv_ok_; + } + + uv_mutex_unlock(&uv__pipe_pair_lock); + + return err; +} + + + int uv_pipe_bind(uv_pipe_t* handle, const char* name) { struct sockaddr_un saddr; const char* pipe_fname; diff --git a/deps/uv/src/unix/process.c b/deps/uv/src/unix/process.c index 5581d8b8099..becf60fe3e7 100644 --- a/deps/uv/src/unix/process.c +++ b/deps/uv/src/unix/process.c @@ -63,10 +63,7 @@ static void uv__chld(EV_P_ ev_child* watcher, int revents) { } -#define UV__F_IPC (1 << 0) -#define UV__F_NONBLOCK (1 << 1) - -static int uv__make_socketpair(int fds[2], int flags) { +int uv__make_socketpair(int fds[2], int flags) { #ifdef SOCK_NONBLOCK int fl; @@ -103,7 +100,7 @@ static int uv__make_socketpair(int fds[2], int flags) { } -static int uv__make_pipe(int fds[2], int flags) { +int uv__make_pipe(int fds[2], int flags) { #if HAVE_SYS_PIPE2 int fl; diff --git a/deps/uv/src/win/pipe.c b/deps/uv/src/win/pipe.c index 5c20fe4801d..53ab6f94114 100644 --- a/deps/uv/src/win/pipe.c +++ b/deps/uv/src/win/pipe.c @@ -91,6 +91,12 @@ int uv_pipe_init(uv_loop_t* loop, uv_pipe_t* handle, int ipc) { } +uv_err_t uv_pipe_pair(uv_pipe_t* a, uv_pipe_t* b) { + /* Implement me */ + return uv__new_artificial_error(UV_ENOSYS); +} + + static void uv_pipe_connection_init(uv_pipe_t* handle) { uv_connection_init((uv_stream_t*) handle); handle->read_req.data = handle; diff --git a/deps/uv/test/test-list.h b/deps/uv/test/test-list.h index 4fcc055e124..3560af1640d 100644 --- a/deps/uv/test/test-list.h +++ b/deps/uv/test/test-list.h @@ -29,6 +29,7 @@ TEST_DECLARE (tcp_ping_pong_v6) TEST_DECLARE (tcp_ref) TEST_DECLARE (tcp_ref2) TEST_DECLARE (pipe_ping_pong) +TEST_DECLARE (pipe_pair) TEST_DECLARE (delayed_accept) TEST_DECLARE (multiple_listen) TEST_DECLARE (tcp_writealot) @@ -165,6 +166,8 @@ TASK_LIST_START TEST_ENTRY (pipe_ping_pong) TEST_HELPER (pipe_ping_pong, pipe_echo_server) + TEST_ENTRY (pipe_pair) + TEST_ENTRY (delayed_accept) TEST_ENTRY (multiple_listen) diff --git a/deps/uv/test/test-pipe-pair.c b/deps/uv/test/test-pipe-pair.c new file mode 100644 index 00000000000..0d973903463 --- /dev/null +++ b/deps/uv/test/test-pipe-pair.c @@ -0,0 +1,137 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "uv.h" +#include "task.h" + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#define PING "PING" + +static uv_pipe_t a; +static uv_pipe_t b; +static uv_write_t req; +static uv_buf_t buf; +static enum { + STATE_MAIN_START, + STATE_THREAD_START, + STATE_MAIN_CLOSE, + STATE_THREAD_CLOSE, +} state; + + +static void pinger_read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf) { + ASSERT(state == STATE_MAIN_CLOSE); + state = STATE_THREAD_CLOSE; + + ASSERT((uv_pipe_t*)stream == &b); + + ASSERT(nread < 0); + ASSERT(uv_last_error(stream->loop).code == UV_EOF); + + free(buf.base); + + uv_close((uv_handle_t*)stream, NULL); +} + + +static void main_thread_read_cb(uv_stream_t* stream, ssize_t nread, + uv_buf_t buf) { + ASSERT(state == STATE_THREAD_START); + state = STATE_MAIN_CLOSE; + + ASSERT((uv_pipe_t*)stream == &a); + ASSERT(stream->loop == uv_default_loop()); + + if (nread > 0) { + ASSERT(strcmp(buf.base, PING) == 0); + uv_close((uv_handle_t*)stream, NULL); + } + + free(buf.base); +} + + +static uv_buf_t alloc_cb(uv_handle_t* handle, size_t size) { + uv_buf_t buf; + buf.base = (char*)malloc(size); + buf.len = size; + return buf; +} + + +void start(void* data) { + uv_loop_t* loop; + int r; + + ASSERT(state == STATE_MAIN_START); + state = STATE_THREAD_START; + + loop = data; + + buf = uv_buf_init(PING, strlen(PING)); + + if (uv_write(&req, (uv_stream_t*)&b, &buf, 1, NULL)) { + FATAL("uv_write failed"); + } + + uv_read_start((uv_stream_t*)&b, alloc_cb, pinger_read_cb); + + uv_run(loop); + + ASSERT(state == STATE_THREAD_CLOSE); +} + + +TEST_IMPL(pipe_pair) { + int r; + uv_err_t err; + uv_thread_t tid; + uv_loop_t* loop; + + state = STATE_MAIN_START; + + r = uv_pipe_init(uv_default_loop(), &a, 1); + ASSERT(r == 0); + + loop = uv_loop_new(); + ASSERT(loop); + + r = uv_pipe_init(loop, &b, 1); + ASSERT(r == 0); + + err = uv_pipe_pair(&a, &b); + ASSERT(err.code == UV_OK); + + r = uv_thread_create(&tid, start, loop); + ASSERT(r == 0); + + uv_read_start((uv_stream_t*)&a, alloc_cb, main_thread_read_cb); + + uv_run(uv_default_loop()); + uv_thread_join(&tid); + + ASSERT(state == STATE_THREAD_CLOSE); + + return 0; +} diff --git a/deps/uv/uv.gyp b/deps/uv/uv.gyp index 3ed20ec6d9c..57d6a345141 100644 --- a/deps/uv/uv.gyp +++ b/deps/uv/uv.gyp @@ -302,6 +302,7 @@ 'test/test-ping-pong.c', 'test/test-pipe-bind-error.c', 'test/test-pipe-connect-error.c', + 'test/test-pipe-pair.c', 'test/test-platform-output.c', 'test/test-process-title.c', 'test/test-ref.c', |