diff --git a/README.md b/README.md index 1359742f..ca8fc2e3 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ http://nodejs.org/ * Child process spawning - * Asynchronous DNS via c-ares or `uv_getaddrinfo`. + * Asynchronous DNS via `uv_getaddrinfo`. * Asynchronous file system APIs `uv_fs_*` diff --git a/config-mingw.mk b/config-mingw.mk index 8a253bae..14afc67e 100644 --- a/config-mingw.mk +++ b/config-mingw.mk @@ -37,7 +37,7 @@ RUNNER_LINKFLAGS=$(LINKFLAGS) RUNNER_LIBS=-lws2_32 -lpsapi -liphlpapi RUNNER_SRC=test/runner-win.c -uv.a: $(WIN_OBJS) src/cares.o src/fs-poll.o src/inet.o src/uv-common.o $(CARES_OBJS) +uv.a: $(WIN_OBJS) src/fs-poll.o src/inet.o src/uv-common.o $(CARES_OBJS) $(AR) rcs uv.a $^ src/%.o: src/%.c include/uv.h include/uv-private/uv-win.h diff --git a/config-unix.mk b/config-unix.mk index 667e7b94..be38ba01 100644 --- a/config-unix.mk +++ b/config-unix.mk @@ -131,7 +131,7 @@ endif RUNNER_LIBS= RUNNER_SRC=test/runner-unix.c -uv.a: $(OBJS) src/cares.o src/fs-poll.o src/inet.o src/uv-common.o src/unix/ev/ev.o src/unix/uv-eio.o src/unix/eio/eio.o $(CARES_OBJS) +uv.a: $(OBJS) src/fs-poll.o src/inet.o src/uv-common.o src/unix/ev/ev.o src/unix/uv-eio.o src/unix/eio/eio.o $(CARES_OBJS) $(AR) rcs uv.a $^ src/%.o: src/%.c include/uv.h include/uv-private/uv-unix.h diff --git a/include/uv.h b/include/uv.h index 1f8becab..19fa6e04 100644 --- a/include/uv.h +++ b/include/uv.h @@ -30,16 +30,14 @@ extern "C" { #ifdef _WIN32 /* Windows - set up dll import/export decorators. */ # if defined(BUILDING_UV_SHARED) - /* Building shared library. Export everything from c-ares as well. */ + /* Building shared library. */ # define UV_EXTERN __declspec(dllexport) -# define CARES_BUILDING_LIBRARY 1 # elif defined(USING_UV_SHARED) - /* Using shared library. Use shared c-ares as well. */ + /* Using shared library. */ # define UV_EXTERN __declspec(dllimport) # else - /* Building static library. Build c-ares statically as well. */ + /* Building static library. */ # define UV_EXTERN /* nothing */ -# define CARES_STATICLIB 1 # endif #elif __GNUC__ >= 4 # define UV_EXTERN __attribute__((visibility("default"))) @@ -55,8 +53,6 @@ extern "C" { #include /* int64_t */ #include /* size_t */ -#include "ares.h" - #if defined(__unix__) || defined(__POSIX__) || defined(__APPLE__) # include "uv-private/uv-unix.h" #else @@ -161,7 +157,6 @@ typedef enum { #define XX(uc, lc) UV_##uc, UV_HANDLE_TYPE_MAP(XX) #undef XX - UV_ARES_TASK, UV_FILE, UV_HANDLE_TYPE_MAX } uv_handle_type; @@ -178,7 +173,6 @@ typedef enum { /* Handle types. */ typedef struct uv_loop_s uv_loop_t; -typedef struct uv_ares_task_s uv_ares_task_t; typedef struct uv_err_s uv_err_t; typedef struct uv_handle_s uv_handle_t; typedef struct uv_stream_s uv_stream_t; @@ -1137,14 +1131,6 @@ UV_EXTERN void uv_timer_set_repeat(uv_timer_t* timer, int64_t repeat); UV_EXTERN int64_t uv_timer_get_repeat(uv_timer_t* timer); -/* c-ares integration initialize and terminate */ -UV_EXTERN int uv_ares_init_options(uv_loop_t*, - ares_channel *channelptr, struct ares_options *options, int optmask); - -/* TODO remove the loop argument from this function? */ -UV_EXTERN void uv_ares_destroy(uv_loop_t*, ares_channel channel); - - /* * uv_getaddrinfo_t is a subclass of uv_req_t * @@ -1786,13 +1772,6 @@ struct uv_counters_s { struct uv_loop_s { UV_LOOP_PRIVATE_FIELDS - ares_channel channel; - /* While the channel is active this timer is called once per second to be */ - /* sure that we're always calling ares_process. See the warning above the */ - /* definition of ares_timeout(). */ - uv_timer_t ares_timer; \ - /* RB_HEAD(uv__ares_tasks, uv_ares_task_t) */ - struct uv__ares_tasks { uv_ares_task_t* rbh_root; } ares_handles; /* Diagnostic counters */ uv_counters_t counters; /* The last error */ diff --git a/src/cares.c b/src/cares.c deleted file mode 100644 index c0acbec8..00000000 --- a/src/cares.c +++ /dev/null @@ -1,225 +0,0 @@ -/* 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 "tree.h" -#include "uv-common.h" - -#include -#include -#include -#include - - -struct uv_ares_task_s { - UV_HANDLE_FIELDS - ares_socket_t sock; - uv_poll_t poll_watcher; - RB_ENTRY(uv_ares_task_s) node; -}; - - -static int cmp_ares_tasks(const uv_ares_task_t* a, const uv_ares_task_t* b) { - if (a->sock < b->sock) return -1; - if (a->sock > b->sock) return 1; - return 0; -} - - -RB_GENERATE_STATIC(uv__ares_tasks, uv_ares_task_s, node, cmp_ares_tasks) - - -/* Add ares handle to list. */ -static void uv_add_ares_handle(uv_loop_t* loop, uv_ares_task_t* handle) { - assert(loop == handle->loop); - RB_INSERT(uv__ares_tasks, &loop->ares_handles, handle); -} - - -/* Find matching ares handle in list. */ -static uv_ares_task_t* uv_find_ares_handle(uv_loop_t* loop, ares_socket_t sock) { - uv_ares_task_t handle; - handle.sock = sock; - return RB_FIND(uv__ares_tasks, &loop->ares_handles, &handle); -} - - -/* Remove ares handle from list. */ -static void uv_remove_ares_handle(uv_ares_task_t* handle) { - RB_REMOVE(uv__ares_tasks, &handle->loop->ares_handles, handle); -} - - -/* Returns 1 if the ares_handles list is empty, 0 otherwise. */ -static int uv_ares_handles_empty(uv_loop_t* loop) { - return RB_EMPTY(&loop->ares_handles); -} - - -/* This is called once per second by loop->timer. It is used to constantly */ -/* call back into c-ares for possibly processing timeouts. */ -static void uv__ares_timeout(uv_timer_t* handle, int status) { - assert(!uv_ares_handles_empty(handle->loop)); - ares_process_fd(handle->loop->channel, ARES_SOCKET_BAD, ARES_SOCKET_BAD); -} - - -static void uv__ares_poll_cb(uv_poll_t* watcher, int status, int events) { - uv_loop_t* loop = watcher->loop; - uv_ares_task_t* task = container_of(watcher, uv_ares_task_t, poll_watcher); - - /* Reset the idle timer */ - uv_timer_again(&loop->ares_timer); - - if (status < 0) { - /* An error happened. Just pretend that the socket is both readable and */ - /* writable. */ - ares_process_fd(loop->channel, task->sock, task->sock); - return; - } - - /* Process DNS responses */ - ares_process_fd(loop->channel, - events & UV_READABLE ? task->sock : ARES_SOCKET_BAD, - events & UV_WRITABLE ? task->sock : ARES_SOCKET_BAD); -} - - -static void uv__ares_poll_close_cb(uv_handle_t* watcher) { - uv_ares_task_t* task = container_of(watcher, uv_ares_task_t, poll_watcher); - free(task); -} - - -/* Allocates and returns a new uv_ares_task_t */ -static uv_ares_task_t* uv__ares_task_create(uv_loop_t* loop, ares_socket_t sock) { - uv_ares_task_t* task = (uv_ares_task_t*) malloc(sizeof *task); - - if (task == NULL) { - /* Out of memory. */ - return NULL; - } - - task->loop = loop; - task->sock = sock; - - if (uv_poll_init_socket(loop, &task->poll_watcher, sock) < 0) { - /* This should never happen. */ - free(task); - return NULL; - } - - return task; -} - - -/* Callback from ares when socket operation is started */ -static void uv__ares_sockstate_cb(void* data, ares_socket_t sock, - int read, int write) { - uv_loop_t* loop = (uv_loop_t*) data; - uv_ares_task_t* task; - - task = uv_find_ares_handle(loop, sock); - - if (read || write) { - if (!task) { - /* New socket */ - - /* If this is the first socket then start the timer. */ - if (!uv_is_active((uv_handle_t*) &loop->ares_timer)) { - assert(uv_ares_handles_empty(loop)); - uv_timer_start(&loop->ares_timer, uv__ares_timeout, 1000, 1000); - } - - task = uv__ares_task_create(loop, sock); - if (task == NULL) { - /* This should never happen unless we're out of memory or something */ - /* is seriously wrong. The socket won't be polled, but the the query */ - /* will eventually time out. */ - return; - } - - uv_add_ares_handle(loop, task); - } - - /* This should never fail. If it fails anyway, the query will eventually */ - /* time out. */ - uv_poll_start(&task->poll_watcher, - (read ? UV_READABLE : 0) | (write ? UV_WRITABLE : 0), - uv__ares_poll_cb); - - } else { - /* read == 0 and write == 0 this is c-ares's way of notifying us that */ - /* the socket is now closed. We must free the data associated with */ - /* socket. */ - assert(task && - "When an ares socket is closed we should have a handle for it"); - - uv_remove_ares_handle(task); - uv_close((uv_handle_t*) &task->poll_watcher, uv__ares_poll_close_cb); - - if (uv_ares_handles_empty(loop)) { - uv_timer_stop(&loop->ares_timer); - } - } -} - - -/* C-ares integration initialize and terminate */ -int uv_ares_init_options(uv_loop_t* loop, ares_channel *channelptr, - struct ares_options *options, int optmask) { - int rc; - - /* only allow single init at a time */ - if (loop->channel != NULL) { - uv__set_artificial_error(loop, UV_EALREADY); - return -1; - } - - /* set our callback as an option */ - options->sock_state_cb = uv__ares_sockstate_cb; - options->sock_state_cb_data = loop; - optmask |= ARES_OPT_SOCK_STATE_CB; - - /* We do the call to ares_init_option for caller. */ - rc = ares_init_options(channelptr, options, optmask); - - /* if success, save channel */ - if (rc == ARES_SUCCESS) { - loop->channel = *channelptr; - } - - /* Initialize the timeout timer. The timer won't be started until the */ - /* first socket is opened. */ - uv_timer_init(loop, &loop->ares_timer); - - return rc; -} - - -void uv_ares_destroy(uv_loop_t* loop, ares_channel channel) { - /* Only allow destroy if did init. */ - if (loop->channel) { - uv_timer_stop(&loop->ares_timer); - ares_destroy(channel); - loop->channel = NULL; - } -} diff --git a/src/unix/loop.c b/src/unix/loop.c index fcf9faf3..bd91c01f 100644 --- a/src/unix/loop.c +++ b/src/unix/loop.c @@ -36,7 +36,6 @@ int uv__loop_init(uv_loop_t* loop, int default_loop) { memset(loop, 0, sizeof(*loop)); - RB_INIT(&loop->ares_handles); RB_INIT(&loop->timer_handles); ngx_queue_init(&loop->active_reqs); ngx_queue_init(&loop->idle_handles); @@ -45,7 +44,6 @@ int uv__loop_init(uv_loop_t* loop, int default_loop) { ngx_queue_init(&loop->prepare_handles); ngx_queue_init(&loop->handle_queue); loop->closing_handles = NULL; - loop->channel = NULL; loop->time = uv_hrtime() / 1000000; loop->async_pipefd[0] = -1; loop->async_pipefd[1] = -1; @@ -65,7 +63,6 @@ int uv__loop_init(uv_loop_t* loop, int default_loop) { void uv__loop_delete(uv_loop_t* loop) { - uv_ares_destroy(loop, loop->channel); ev_loop_destroy(loop->ev); #if __linux__ if (loop->inotify_fd != -1) { diff --git a/src/win/core.c b/src/win/core.c index 7a355803..e288fc4c 100644 --- a/src/win/core.c +++ b/src/win/core.c @@ -92,9 +92,6 @@ static void uv_loop_init(uv_loop_t* loop) { memset(&loop->poll_peer_sockets, 0, sizeof loop->poll_peer_sockets); - loop->channel = NULL; - RB_INIT(&loop->ares_handles); - loop->active_tcp_streams = 0; loop->active_udp_streams = 0; diff --git a/uv.gyp b/uv.gyp index 47eaa705..052ae345 100644 --- a/uv.gyp +++ b/uv.gyp @@ -50,7 +50,6 @@ 'include/uv.h', 'include/uv-private/ngx-queue.h', 'include/uv-private/tree.h', - 'src/cares.c', 'src/fs-poll.c', 'src/inet.c', 'src/uv-common.c',