diff --git a/deps/uv/include/uv-private/uv-unix.h b/deps/uv/include/uv-private/uv-unix.h index b7f01ae77d..6b6272cca5 100644 --- a/deps/uv/include/uv-private/uv-unix.h +++ b/deps/uv/include/uv-private/uv-unix.h @@ -117,9 +117,7 @@ typedef int uv_file; /* UV_NAMED_PIPE */ -#define UV_PIPE_PRIVATE_TYPEDEF #define UV_PIPE_PRIVATE_FIELDS \ - UV_TCP_PRIVATE_FIELDS \ const char* pipe_fname; /* strdup'ed */ diff --git a/deps/uv/include/uv.h b/deps/uv/include/uv.h index 5b1144ef22..e42509e99e 100644 --- a/deps/uv/include/uv.h +++ b/deps/uv/include/uv.h @@ -200,7 +200,6 @@ typedef enum { UV_ASYNC, UV_ARES_TASK, UV_ARES_EVENT, - UV_GETADDRINFO, UV_PROCESS } uv_handle_type; @@ -215,6 +214,7 @@ typedef enum { UV_UDP_SEND, UV_FS, UV_WORK, + UV_GETADDRINFO, UV_REQ_TYPE_PRIVATE } uv_req_type; @@ -737,14 +737,14 @@ void uv_ares_destroy(uv_loop_t*, ares_channel channel); /* - * uv_getaddrinfo_t is a subclass of uv_handle_t - * - * TODO this should be a subclass of uv_req_t + * uv_getaddrinfo_t is a subclass of uv_req_t * * Request object for uv_getaddrinfo. */ struct uv_getaddrinfo_s { - UV_HANDLE_FIELDS + UV_REQ_FIELDS + /* read-only */ + uv_loop_t* loop; \ UV_GETADDRINFO_PRIVATE_FIELDS }; diff --git a/deps/uv/src/unix/core.c b/deps/uv/src/unix/core.c index 45fef16b62..57306ac002 100644 --- a/deps/uv/src/unix/core.c +++ b/deps/uv/src/unix/core.c @@ -607,7 +607,7 @@ static void getaddrinfo_thread_proc(eio_req *req) { /* stub implementation of uv_getaddrinfo */ -int uv_getaddrinfo(uv_loop_t* loop, +int uv_getaddrinfo(uv_loop_t* loop, uv_getaddrinfo_t* handle, uv_getaddrinfo_cb cb, const char* hostname, @@ -622,7 +622,10 @@ int uv_getaddrinfo(uv_loop_t* loop, return -1; } - memset(handle, 0, sizeof(uv_getaddrinfo_t)); + uv__req_init((uv_req_t*)handle); + handle->type = UV_GETADDRINFO; + handle->loop = loop; + handle->cb = cb; /* TODO don't alloc so much. */ @@ -633,10 +636,10 @@ int uv_getaddrinfo(uv_loop_t* loop, /* TODO security! check lengths, check return values. */ - handle->loop = loop; - handle->cb = cb; handle->hostname = hostname ? strdup(hostname) : NULL; handle->service = service ? strdup(service) : NULL; + handle->res = NULL; + handle->retcode = 0; /* TODO check handle->hostname == NULL */ /* TODO check handle->service == NULL */ diff --git a/deps/uv/src/unix/internal.h b/deps/uv/src/unix/internal.h index 024a9b377a..f5677c7620 100644 --- a/deps/uv/src/unix/internal.h +++ b/deps/uv/src/unix/internal.h @@ -80,6 +80,8 @@ uv_err_t uv_err_new_artificial(uv_loop_t* loop, int code); void uv_fatal_error(const int errorno, const char* syscall); /* stream */ +void uv__stream_init(uv_loop_t* loop, uv_stream_t* stream, + uv_handle_type type); int uv__stream_open(uv_stream_t*, int fd, int flags); void uv__stream_io(EV_P_ ev_io* watcher, int revents); void uv__server_io(EV_P_ ev_io* watcher, int revents); diff --git a/deps/uv/src/unix/pipe.c b/deps/uv/src/unix/pipe.c index 6f1d816822..fb420dd55f 100644 --- a/deps/uv/src/unix/pipe.c +++ b/deps/uv/src/unix/pipe.c @@ -30,24 +30,9 @@ #include int uv_pipe_init(uv_loop_t* loop, uv_pipe_t* handle) { - memset(handle, 0, sizeof *handle); - - uv__handle_init(loop, (uv_handle_t*)handle, UV_NAMED_PIPE); + uv__stream_init(loop, (uv_stream_t*)handle, UV_NAMED_PIPE); loop->counters.pipe_init++; - - handle->type = UV_NAMED_PIPE; - handle->pipe_fname = NULL; /* Only set by listener. */ - - ev_init(&handle->write_watcher, uv__stream_io); - ev_init(&handle->read_watcher, uv__stream_io); - handle->write_watcher.data = handle; - handle->read_watcher.data = handle; - handle->accepted_fd = -1; - handle->fd = -1; - - ngx_queue_init(&handle->write_completed_queue); - ngx_queue_init(&handle->write_queue); - + handle->pipe_fname = NULL; return 0; } diff --git a/deps/uv/src/unix/stream.c b/deps/uv/src/unix/stream.c index 0b5a2a4c06..b48f216a82 100644 --- a/deps/uv/src/unix/stream.c +++ b/deps/uv/src/unix/stream.c @@ -47,6 +47,34 @@ static size_t uv__buf_count(uv_buf_t bufs[], int bufcnt) { } +void uv__stream_init(uv_loop_t* loop, + uv_stream_t* stream, + uv_handle_type type) { + uv__handle_init(loop, (uv_handle_t*)stream, type); + + stream->alloc_cb = NULL; + stream->close_cb = NULL; + stream->connection_cb = NULL; + stream->connect_req = NULL; + stream->accepted_fd = -1; + stream->fd = -1; + stream->delayed_error = 0; + ngx_queue_init(&stream->write_queue); + ngx_queue_init(&stream->write_completed_queue); + stream->write_queue_size = 0; + + ev_init(&stream->read_watcher, uv__stream_io); + stream->read_watcher.data = stream; + + ev_init(&stream->write_watcher, uv__stream_io); + stream->write_watcher.data = stream; + + assert(ngx_queue_empty(&stream->write_queue)); + assert(ngx_queue_empty(&stream->write_completed_queue)); + assert(stream->write_queue_size == 0); +} + + int uv__stream_open(uv_stream_t* stream, int fd, int flags) { socklen_t yes; diff --git a/deps/uv/src/unix/tcp.c b/deps/uv/src/unix/tcp.c index fb402e7e6b..9f14c1b6c0 100644 --- a/deps/uv/src/unix/tcp.c +++ b/deps/uv/src/unix/tcp.c @@ -27,28 +27,8 @@ int uv_tcp_init(uv_loop_t* loop, uv_tcp_t* tcp) { - uv__handle_init(loop, (uv_handle_t*)tcp, UV_TCP); + uv__stream_init(loop, (uv_stream_t*)tcp, UV_TCP); loop->counters.tcp_init++; - - tcp->alloc_cb = NULL; - tcp->connect_req = NULL; - tcp->accepted_fd = -1; - tcp->fd = -1; - tcp->delayed_error = 0; - ngx_queue_init(&tcp->write_queue); - ngx_queue_init(&tcp->write_completed_queue); - tcp->write_queue_size = 0; - - ev_init(&tcp->read_watcher, uv__stream_io); - tcp->read_watcher.data = tcp; - - ev_init(&tcp->write_watcher, uv__stream_io); - tcp->write_watcher.data = tcp; - - assert(ngx_queue_empty(&tcp->write_queue)); - assert(ngx_queue_empty(&tcp->write_completed_queue)); - assert(tcp->write_queue_size == 0); - return 0; } diff --git a/deps/uv/src/win/getaddrinfo.c b/deps/uv/src/win/getaddrinfo.c index ae95888f9f..19b5f28703 100644 --- a/deps/uv/src/win/getaddrinfo.c +++ b/deps/uv/src/win/getaddrinfo.c @@ -255,6 +255,8 @@ int uv_getaddrinfo(uv_loop_t* loop, goto error; } + uv_req_init((uv_req_init*)handle); + handle->getaddrinfo_cb = getaddrinfo_cb; handle->res = NULL; handle->type = UV_GETADDRINFO; diff --git a/deps/uv/test/test-getaddrinfo.c b/deps/uv/test/test-getaddrinfo.c index a66941d453..9cd9be4f5c 100644 --- a/deps/uv/test/test-getaddrinfo.c +++ b/deps/uv/test/test-getaddrinfo.c @@ -51,15 +51,20 @@ static void getaddrinfo_cuncurrent_cb(uv_getaddrinfo_t* handle, int status, struct addrinfo* res) { int i; + int* data = (int*)handle->data; for (i = 0; i < CONCURRENT_COUNT; i++) { if (&getaddrinfo_handles[i] == handle) { + ASSERT(i == *data); + callback_counts[i]++; break; } } ASSERT (i < CONCURRENT_COUNT); + free(data); + getaddrinfo_cbs++; } @@ -88,12 +93,17 @@ TEST_IMPL(getaddrinfo_basic) { TEST_IMPL(getaddrinfo_concurrent) { int i, r; + int* data; uv_init(); for (i = 0; i < CONCURRENT_COUNT; i++) { callback_counts[i] = 0; + data = (int*)malloc(sizeof(int)); + *data = i; + getaddrinfo_handles[i].data = data; + r = uv_getaddrinfo(uv_default_loop(), &getaddrinfo_handles[i], &getaddrinfo_cuncurrent_cb,