Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

unix: Fix test-gethostbyname

  • Loading branch information...
ry committed Aug 31, 2011
1 parent 6fd340b commit 836cc204b6b73b6b6d5d5a456f1b9b3ecdeefc80
Showing with 17 additions and 9 deletions.
  1. +14 −8 src/unix/cares.c
  2. +3 −0 src/unix/core.c
  3. +0 −1 test/test-gethostbyname.c
@@ -27,25 +27,29 @@
#include <stdlib.h>


#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;
@@ -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;
}

@@ -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);
}

0 comments on commit 836cc20

Please sign in to comment.
You can’t perform that action at this time.