aboutsummaryrefslogtreecommitdiff
path: root/deps/uv/src/win/getaddrinfo.c
diff options
context:
space:
mode:
Diffstat (limited to 'deps/uv/src/win/getaddrinfo.c')
-rw-r--r--deps/uv/src/win/getaddrinfo.c53
1 files changed, 16 insertions, 37 deletions
diff --git a/deps/uv/src/win/getaddrinfo.c b/deps/uv/src/win/getaddrinfo.c
index c2017ef768..fb4ab0a602 100644
--- a/deps/uv/src/win/getaddrinfo.c
+++ b/deps/uv/src/win/getaddrinfo.c
@@ -56,26 +56,6 @@
#define ALIGNED_SIZE(X) ((((X) + 3) >> 2) << 2)
-/*
- * getaddrinfo error code mapping
- * Falls back to uv_translate_sys_error if no match
- */
-static uv_err_code uv_translate_eai_error(int eai_errno) {
- switch (eai_errno) {
- case ERROR_SUCCESS: return UV_OK;
- case EAI_BADFLAGS: return UV_EBADF;
- case EAI_FAIL: return UV_EFAULT;
- case EAI_FAMILY: return UV_EAIFAMNOSUPPORT;
- case EAI_MEMORY: return UV_ENOMEM;
- case EAI_NONAME: return UV_ENOENT;
- case EAI_AGAIN: return UV_EAGAIN;
- case EAI_SERVICE: return UV_EAISERVICE;
- case EAI_SOCKTYPE: return UV_EAISOCKTYPE;
- default: return uv_translate_sys_error(eai_errno);
- }
-}
-
-
/* getaddrinfo worker thread implementation */
static DWORD WINAPI getaddrinfo_thread_proc(void* parameter) {
uv_getaddrinfo_t* req = (uv_getaddrinfo_t*) parameter;
@@ -115,7 +95,7 @@ void uv_process_getaddrinfo_req(uv_loop_t* loop, uv_getaddrinfo_t* req) {
struct addrinfo* addrinfo_ptr;
char* alloc_ptr = NULL;
char* cur_ptr = NULL;
- int status = 0;
+ int err = 0;
/* release input parameter memory */
if (req->alloc != NULL) {
@@ -133,8 +113,8 @@ void uv_process_getaddrinfo_req(uv_loop_t* loop, uv_getaddrinfo_t* req) {
if (addrinfow_ptr->ai_canonname != NULL) {
name_len = uv_utf16_to_utf8(addrinfow_ptr->ai_canonname, -1, NULL, 0);
if (name_len == 0) {
- uv__set_sys_error(loop, GetLastError());
- status = -1;
+ /* FIXME(bnoordhuis) Retain GetLastError(). */
+ err = UV_EAI_SYSTEM;
goto complete;
}
addrinfo_len += ALIGNED_SIZE(name_len);
@@ -199,13 +179,11 @@ void uv_process_getaddrinfo_req(uv_loop_t* loop, uv_getaddrinfo_t* req) {
}
}
} else {
- uv__set_artificial_error(loop, UV_ENOMEM);
- status = -1;
+ err = UV_EAI_MEMORY;
}
} else {
/* GetAddrInfo failed */
- uv__set_artificial_error(loop, uv_translate_eai_error(req->retcode));
- status = -1;
+ err = uv__getaddrinfo_translate_error(req->retcode);
}
/* return memory to system */
@@ -218,7 +196,7 @@ complete:
uv__req_unregister(loop, req);
/* finally do callback with converted result */
- req->getaddrinfo_cb(req, status, (struct addrinfo*)alloc_ptr);
+ req->getaddrinfo_cb(req, err, (struct addrinfo*)alloc_ptr);
}
@@ -238,7 +216,7 @@ void uv_freeaddrinfo(struct addrinfo* ai) {
* and save the UNICODE string pointers in the req
* We also copy hints so that caller does not need to keep memory until the
* callback.
- * return UV_OK if a callback will be made
+ * return 0 if a callback will be made
* return error code if validation fails
*
* To minimize allocation we calculate total size required,
@@ -255,10 +233,11 @@ int uv_getaddrinfo(uv_loop_t* loop,
int servicesize = 0;
int hintssize = 0;
char* alloc_ptr = NULL;
+ int err;
if (req == NULL || getaddrinfo_cb == NULL ||
(node == NULL && service == NULL)) {
- uv__set_sys_error(loop, WSAEINVAL);
+ err = WSAEINVAL;
goto error;
}
@@ -273,7 +252,7 @@ int uv_getaddrinfo(uv_loop_t* loop,
if (node != NULL) {
nodesize = ALIGNED_SIZE(uv_utf8_to_utf16(node, NULL, 0) * sizeof(WCHAR));
if (nodesize == 0) {
- uv__set_sys_error(loop, GetLastError());
+ err = GetLastError();
goto error;
}
}
@@ -282,7 +261,7 @@ int uv_getaddrinfo(uv_loop_t* loop,
servicesize = ALIGNED_SIZE(uv_utf8_to_utf16(service, NULL, 0) *
sizeof(WCHAR));
if (servicesize == 0) {
- uv__set_sys_error(loop, GetLastError());
+ err = GetLastError();
goto error;
}
}
@@ -293,7 +272,7 @@ int uv_getaddrinfo(uv_loop_t* loop,
/* allocate memory for inputs, and partition it as needed */
alloc_ptr = (char*)malloc(nodesize + servicesize + hintssize);
if (!alloc_ptr) {
- uv__set_sys_error(loop, WSAENOBUFS);
+ err = WSAENOBUFS;
goto error;
}
@@ -307,7 +286,7 @@ int uv_getaddrinfo(uv_loop_t* loop,
if (uv_utf8_to_utf16(node,
(WCHAR*) alloc_ptr,
nodesize / sizeof(WCHAR)) == 0) {
- uv__set_sys_error(loop, GetLastError());
+ err = GetLastError();
goto error;
}
alloc_ptr += nodesize;
@@ -322,7 +301,7 @@ int uv_getaddrinfo(uv_loop_t* loop,
if (uv_utf8_to_utf16(service,
(WCHAR*) alloc_ptr,
servicesize / sizeof(WCHAR)) == 0) {
- uv__set_sys_error(loop, GetLastError());
+ err = GetLastError();
goto error;
}
alloc_ptr += servicesize;
@@ -349,7 +328,7 @@ int uv_getaddrinfo(uv_loop_t* loop,
if (QueueUserWorkItem(&getaddrinfo_thread_proc,
req,
WT_EXECUTELONGFUNCTION) == 0) {
- uv__set_sys_error(loop, GetLastError());
+ err = GetLastError();
goto error;
}
@@ -361,5 +340,5 @@ error:
if (req != NULL && req->alloc != NULL) {
free(req->alloc);
}
- return -1;
+ return uv_translate_sys_error(err);
}