unix: clarify that uv_getaddrinfo_t is a req

This commit is contained in:
Ben Noordhuis 2012-06-22 16:39:20 +02:00
parent ea3e2cd480
commit f01e9d708a
2 changed files with 37 additions and 34 deletions

View File

@ -180,7 +180,7 @@ typedef enum {
} uv_req_type; } uv_req_type;
/* Handle types. */
typedef struct uv_loop_s uv_loop_t; typedef struct uv_loop_s uv_loop_t;
typedef struct uv_ares_task_s uv_ares_task_t; typedef struct uv_ares_task_s uv_ares_task_t;
typedef struct uv_err_s uv_err_t; typedef struct uv_err_s uv_err_t;
@ -196,23 +196,25 @@ typedef struct uv_prepare_s uv_prepare_t;
typedef struct uv_check_s uv_check_t; typedef struct uv_check_s uv_check_t;
typedef struct uv_idle_s uv_idle_t; typedef struct uv_idle_s uv_idle_t;
typedef struct uv_async_s uv_async_t; typedef struct uv_async_s uv_async_t;
typedef struct uv_getaddrinfo_s uv_getaddrinfo_t;
typedef struct uv_process_s uv_process_t; typedef struct uv_process_s uv_process_t;
typedef struct uv_counters_s uv_counters_t; typedef struct uv_fs_event_s uv_fs_event_t;
typedef struct uv_cpu_info_s uv_cpu_info_t; typedef struct uv_fs_poll_s uv_fs_poll_t;
typedef struct uv_interface_address_s uv_interface_address_t;
/* Request types */ /* Request types. */
typedef struct uv_req_s uv_req_t; typedef struct uv_req_s uv_req_t;
typedef struct uv_getaddrinfo_s uv_getaddrinfo_t;
typedef struct uv_shutdown_s uv_shutdown_t; typedef struct uv_shutdown_s uv_shutdown_t;
typedef struct uv_write_s uv_write_t; typedef struct uv_write_s uv_write_t;
typedef struct uv_connect_s uv_connect_t; typedef struct uv_connect_s uv_connect_t;
typedef struct uv_udp_send_s uv_udp_send_t; typedef struct uv_udp_send_s uv_udp_send_t;
typedef struct uv_fs_s uv_fs_t; typedef struct uv_fs_s uv_fs_t;
/* uv_fs_event_t is a subclass of uv_handle_t. */
typedef struct uv_fs_event_s uv_fs_event_t;
typedef struct uv_fs_poll_s uv_fs_poll_t;
typedef struct uv_work_s uv_work_t; typedef struct uv_work_s uv_work_t;
/* None of the above. */
typedef struct uv_counters_s uv_counters_t;
typedef struct uv_cpu_info_s uv_cpu_info_t;
typedef struct uv_interface_address_s uv_interface_address_t;
/* /*
* This function must be called before any other functions in libuv. * This function must be called before any other functions in libuv.
@ -1715,7 +1717,6 @@ union uv_any_handle {
uv_idle_t idle; uv_idle_t idle;
uv_async_t async; uv_async_t async;
uv_timer_t timer; uv_timer_t timer;
uv_getaddrinfo_t getaddrinfo;
uv_fs_event_t fs_event; uv_fs_event_t fs_event;
}; };

View File

@ -325,60 +325,62 @@ static int uv_getaddrinfo_done(eio_req* req_) {
} }
static void getaddrinfo_thread_proc(eio_req *req) { static void getaddrinfo_thread_proc(eio_req *req_) {
uv_getaddrinfo_t* handle = req->data; uv_getaddrinfo_t* req = req_->data;
handle->retcode = getaddrinfo(handle->hostname, req->retcode = getaddrinfo(req->hostname,
handle->service, req->service,
handle->hints, req->hints,
&handle->res); &req->res);
} }
/* stub implementation of uv_getaddrinfo */ /* 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_t* req,
uv_getaddrinfo_cb cb, uv_getaddrinfo_cb cb,
const char* hostname, const char* hostname,
const char* service, const char* service,
const struct addrinfo* hints) { const struct addrinfo* hints) {
eio_req* req; eio_req* req_;
uv_eio_init(loop); uv_eio_init(loop);
if (handle == NULL || cb == NULL || if (req == NULL || cb == NULL || (hostname == NULL && service == NULL)) {
(hostname == NULL && service == NULL)) {
uv__set_artificial_error(loop, UV_EINVAL); uv__set_artificial_error(loop, UV_EINVAL);
return -1; return -1;
} }
uv__req_init(loop, handle, UV_GETADDRINFO); uv__req_init(loop, req, UV_GETADDRINFO);
handle->loop = loop; req->loop = loop;
handle->cb = cb; req->cb = cb;
/* TODO don't alloc so much. */ /* TODO don't alloc so much. */
if (hints) { if (hints) {
handle->hints = malloc(sizeof(struct addrinfo)); req->hints = malloc(sizeof(struct addrinfo));
memcpy(handle->hints, hints, sizeof(struct addrinfo)); memcpy(req->hints, hints, sizeof(struct addrinfo));
} }
else { else {
handle->hints = NULL; req->hints = NULL;
} }
/* TODO security! check lengths, check return values. */ /* TODO security! check lengths, check return values. */
handle->hostname = hostname ? strdup(hostname) : NULL; req->hostname = hostname ? strdup(hostname) : NULL;
handle->service = service ? strdup(service) : NULL; req->service = service ? strdup(service) : NULL;
handle->res = NULL; req->res = NULL;
handle->retcode = 0; req->retcode = 0;
/* TODO check handle->hostname == NULL */ /* TODO check handle->hostname == NULL */
/* TODO check handle->service == NULL */ /* TODO check handle->service == NULL */
req = eio_custom(getaddrinfo_thread_proc, EIO_PRI_DEFAULT, req_ = eio_custom(getaddrinfo_thread_proc,
uv_getaddrinfo_done, handle, &loop->uv_eio_channel); EIO_PRI_DEFAULT,
assert(req); uv_getaddrinfo_done,
assert(req->data == handle); req,
&loop->uv_eio_channel);
assert(req_);
return 0; return 0;
} }