Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
unix: Fix test-gethostbyname
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Aug 31, 2011
1 parent 6fd340b commit 836cc20
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
22 changes: 14 additions & 8 deletions src/unix/cares.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/unix/core.c
Expand Up @@ -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);
}


Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
1 change: 0 additions & 1 deletion test/test-gethostbyname.c
Expand Up @@ -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);
}

Expand Down

0 comments on commit 836cc20

Please sign in to comment.