mirror of
https://github.com/libuv/libuv
synced 2025-03-28 21:13:16 +00:00
Subclass uv_getaddrinfo_t from uv_req_t.
This patch also fixes #155. Since we no longer memset clear the uv_getaddrinfo_t, the user can now set the `uv_getaddrinfo_t->data` field without problems.
This commit is contained in:
parent
eb987bcc5c
commit
efa1b54076
10
include/uv.h
10
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
|
||||
};
|
||||
|
||||
|
@ -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 */
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user