unix: clarify that uv_getaddrinfo_t is a req
This commit is contained in:
parent
ea3e2cd480
commit
f01e9d708a
21
include/uv.h
21
include/uv.h
@ -180,7 +180,7 @@ typedef enum {
|
||||
} uv_req_type;
|
||||
|
||||
|
||||
|
||||
/* Handle types. */
|
||||
typedef struct uv_loop_s uv_loop_t;
|
||||
typedef struct uv_ares_task_s uv_ares_task_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_idle_s uv_idle_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_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;
|
||||
/* Request types */
|
||||
typedef struct uv_fs_event_s uv_fs_event_t;
|
||||
typedef struct uv_fs_poll_s uv_fs_poll_t;
|
||||
|
||||
/* Request types. */
|
||||
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_write_s uv_write_t;
|
||||
typedef struct uv_connect_s uv_connect_t;
|
||||
typedef struct uv_udp_send_s uv_udp_send_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;
|
||||
|
||||
/* 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.
|
||||
@ -1715,7 +1717,6 @@ union uv_any_handle {
|
||||
uv_idle_t idle;
|
||||
uv_async_t async;
|
||||
uv_timer_t timer;
|
||||
uv_getaddrinfo_t getaddrinfo;
|
||||
uv_fs_event_t fs_event;
|
||||
};
|
||||
|
||||
|
||||
@ -325,60 +325,62 @@ static int uv_getaddrinfo_done(eio_req* req_) {
|
||||
}
|
||||
|
||||
|
||||
static void getaddrinfo_thread_proc(eio_req *req) {
|
||||
uv_getaddrinfo_t* handle = req->data;
|
||||
static void getaddrinfo_thread_proc(eio_req *req_) {
|
||||
uv_getaddrinfo_t* req = req_->data;
|
||||
|
||||
handle->retcode = getaddrinfo(handle->hostname,
|
||||
handle->service,
|
||||
handle->hints,
|
||||
&handle->res);
|
||||
req->retcode = getaddrinfo(req->hostname,
|
||||
req->service,
|
||||
req->hints,
|
||||
&req->res);
|
||||
}
|
||||
|
||||
|
||||
/* stub implementation of uv_getaddrinfo */
|
||||
int uv_getaddrinfo(uv_loop_t* loop,
|
||||
uv_getaddrinfo_t* handle,
|
||||
uv_getaddrinfo_t* req,
|
||||
uv_getaddrinfo_cb cb,
|
||||
const char* hostname,
|
||||
const char* service,
|
||||
const struct addrinfo* hints) {
|
||||
eio_req* req;
|
||||
eio_req* req_;
|
||||
|
||||
uv_eio_init(loop);
|
||||
|
||||
if (handle == NULL || cb == NULL ||
|
||||
(hostname == NULL && service == NULL)) {
|
||||
if (req == NULL || cb == NULL || (hostname == NULL && service == NULL)) {
|
||||
uv__set_artificial_error(loop, UV_EINVAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
uv__req_init(loop, handle, UV_GETADDRINFO);
|
||||
handle->loop = loop;
|
||||
handle->cb = cb;
|
||||
uv__req_init(loop, req, UV_GETADDRINFO);
|
||||
req->loop = loop;
|
||||
req->cb = cb;
|
||||
|
||||
/* TODO don't alloc so much. */
|
||||
|
||||
if (hints) {
|
||||
handle->hints = malloc(sizeof(struct addrinfo));
|
||||
memcpy(handle->hints, hints, sizeof(struct addrinfo));
|
||||
req->hints = malloc(sizeof(struct addrinfo));
|
||||
memcpy(req->hints, hints, sizeof(struct addrinfo));
|
||||
}
|
||||
else {
|
||||
handle->hints = NULL;
|
||||
req->hints = NULL;
|
||||
}
|
||||
|
||||
/* TODO security! check lengths, check return values. */
|
||||
|
||||
handle->hostname = hostname ? strdup(hostname) : NULL;
|
||||
handle->service = service ? strdup(service) : NULL;
|
||||
handle->res = NULL;
|
||||
handle->retcode = 0;
|
||||
req->hostname = hostname ? strdup(hostname) : NULL;
|
||||
req->service = service ? strdup(service) : NULL;
|
||||
req->res = NULL;
|
||||
req->retcode = 0;
|
||||
|
||||
/* TODO check handle->hostname == NULL */
|
||||
/* TODO check handle->service == NULL */
|
||||
|
||||
req = eio_custom(getaddrinfo_thread_proc, EIO_PRI_DEFAULT,
|
||||
uv_getaddrinfo_done, handle, &loop->uv_eio_channel);
|
||||
assert(req);
|
||||
assert(req->data == handle);
|
||||
req_ = eio_custom(getaddrinfo_thread_proc,
|
||||
EIO_PRI_DEFAULT,
|
||||
uv_getaddrinfo_done,
|
||||
req,
|
||||
&loop->uv_eio_channel);
|
||||
assert(req_);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user