diff --git a/include/uv.h b/include/uv.h index 5b1144ef..e42509e9 100644 --- a/include/uv.h +++ b/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/src/unix/core.c b/src/unix/core.c index 45fef16b..57306ac0 100644 --- a/src/unix/core.c +++ b/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/src/win/getaddrinfo.c b/src/win/getaddrinfo.c index ae95888f..19b5f287 100644 --- a/src/win/getaddrinfo.c +++ b/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/test/test-getaddrinfo.c b/test/test-getaddrinfo.c index a66941d4..9cd9be4f 100644 --- a/test/test-getaddrinfo.c +++ b/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,