unix: port getaddrinfo to new thread pool

This commit is contained in:
Ben Noordhuis 2012-10-01 00:48:47 +02:00
parent f35a4b628a
commit 36c91e3ba0
2 changed files with 10 additions and 20 deletions

View File

@ -243,6 +243,7 @@ typedef struct {
uint64_t repeat;
#define UV_GETADDRINFO_PRIVATE_FIELDS \
struct uv__work work_req; \
uv_getaddrinfo_cb cb; \
struct addrinfo* hints; \
char* hostname; \

View File

@ -27,8 +27,8 @@
#include <string.h>
static void uv__getaddrinfo_work(eio_req *req_) {
uv_getaddrinfo_t* req = req_->data;
static void uv__getaddrinfo_work(struct uv__work* w) {
uv_getaddrinfo_t* req = container_of(w, uv_getaddrinfo_t, work_req);
req->retcode = getaddrinfo(req->hostname,
req->service,
@ -37,8 +37,8 @@ static void uv__getaddrinfo_work(eio_req *req_) {
}
static int uv__getaddrinfo_done(eio_req* req_) {
uv_getaddrinfo_t* req = req_->data;
static void uv__getaddrinfo_done(struct uv__work* w) {
uv_getaddrinfo_t* req = container_of(w, uv_getaddrinfo_t, work_req);
struct addrinfo *res = req->res;
#if __sun
size_t hostlen = strlen(req->hostname);
@ -76,8 +76,6 @@ static int uv__getaddrinfo_done(eio_req* req_) {
}
req->cb(req, req->retcode, res);
return 0;
}
@ -90,15 +88,12 @@ int uv_getaddrinfo(uv_loop_t* loop,
size_t hostname_len;
size_t service_len;
size_t hints_len;
eio_req* req_;
size_t len;
char* buf;
if (req == NULL || cb == NULL || (hostname == NULL && service == NULL))
return uv__set_artificial_error(loop, UV_EINVAL);
uv_eio_init(loop);
hostname_len = hostname ? strlen(hostname) + 1 : 0;
service_len = service ? strlen(service) + 1 : 0;
hints_len = hints ? sizeof(*hints) : 0;
@ -134,18 +129,12 @@ int uv_getaddrinfo(uv_loop_t* loop,
len += hostname_len;
}
req_ = eio_custom(uv__getaddrinfo_work,
EIO_PRI_DEFAULT,
uv__getaddrinfo_done,
req,
&loop->uv_eio_channel);
uv__work_submit(loop,
&req->work_req,
uv__getaddrinfo_work,
uv__getaddrinfo_done);
if (req_)
return 0;
free(buf);
return uv__set_artificial_error(loop, UV_ENOMEM);
return 0;
}