diff --git a/include/uv.h b/include/uv.h index 4fabf7a46..b9c967c14 100644 --- a/include/uv.h +++ b/include/uv.h @@ -111,7 +111,6 @@ typedef intptr_t ssize_t; XX( 40, ETIMEDOUT, "connection timed out") \ XX( 41, ECHARSET, "") \ XX( 42, EAIFAMNOSUPPORT, "") \ - XX( 43, EAINONAME, "") \ XX( 44, EAISERVICE, "") \ XX( 45, EAISOCKTYPE, "") \ XX( 46, ESHUTDOWN, "") \ diff --git a/src/win/error.c b/src/win/error.c index 3db97a10f..12ce4d1b5 100644 --- a/src/win/error.c +++ b/src/win/error.c @@ -69,6 +69,7 @@ uv_err_code uv_translate_sys_error(int sys_errno) { case ERROR_SUCCESS: return UV_OK; case ERROR_FILE_NOT_FOUND: return UV_ENOENT; case ERROR_PATH_NOT_FOUND: return UV_ENOENT; + case ERROR_ACCESS_DENIED: return UV_EACCES; case ERROR_NOACCESS: return UV_EACCES; case WSAEACCES: return UV_EACCES; case ERROR_ADDRESS_ALREADY_ASSOCIATED: return UV_EADDRINUSE; diff --git a/src/win/fs.c b/src/win/fs.c index c6d86b02b..2037ddd6b 100644 --- a/src/win/fs.c +++ b/src/win/fs.c @@ -491,14 +491,36 @@ void fs__readdir(uv_fs_t* req, const wchar_t* path, int flags) { void fs__stat(uv_fs_t* req, const wchar_t* path) { int result; + unsigned short mode; - result = _wstati64(path, &req->stat); + fs__open(req, path, _O_RDONLY, 0); + if (req->result == -1) { + return; + } + + result = _fstati64(req->result, &req->stat); if (result == -1) { req->ptr = NULL; } else { + + /* + * VC CRT doesn't properly set S_IFDIR in _fstati64, + * so we set it here if path is a directory. + */ + if (GetFileAttributesW(path) & FILE_ATTRIBUTE_DIRECTORY) { + mode = req->stat.st_mode; + mode &= ~_S_IFMT; + mode |= _S_IFDIR; + + req->stat.st_mode = mode; + assert((req->stat.st_mode & _S_IFMT) == _S_IFDIR); + } + req->ptr = &req->stat; } + _close(req->result); + SET_REQ_RESULT(req, result); } @@ -687,7 +709,7 @@ void fs__symlink(uv_fs_t* req, const wchar_t* path, const wchar_t* new_path, req->last_error = ERROR_SUCCESS; return; } - + SET_REQ_RESULT(req, result); } @@ -726,7 +748,7 @@ void fs__readlink(uv_fs_t* req, const wchar_t* path) { FSCTL_GET_REPARSE_POINT, NULL, 0, - buffer, + buffer, MAXIMUM_REPARSE_DATA_BUFFER_SIZE, &bytes_returned, NULL); diff --git a/src/win/getaddrinfo.c b/src/win/getaddrinfo.c index f0d854216..5353c0b5f 100644 --- a/src/win/getaddrinfo.c +++ b/src/win/getaddrinfo.c @@ -66,7 +66,7 @@ static uv_err_code uv_translate_eai_error(int eai_errno) { case EAI_FAIL: return UV_EFAULT; case EAI_FAMILY: return UV_EAIFAMNOSUPPORT; case EAI_MEMORY: return UV_ENOMEM; - case EAI_NONAME: return UV_EAINONAME; + case EAI_NONAME: return UV_ENOENT; case EAI_AGAIN: return UV_EAGAIN; case EAI_SERVICE: return UV_EAISERVICE; case EAI_SOCKTYPE: return UV_EAISOCKTYPE; @@ -117,7 +117,7 @@ void uv_process_getaddrinfo_req(uv_loop_t* loop, uv_getaddrinfo_t* handle, struct addrinfo* addrinfo_ptr; char* alloc_ptr = NULL; char* cur_ptr = NULL; - uv_err_code uv_ret; + int status = 0; /* release input parameter memory */ if (handle->alloc != NULL) { @@ -125,7 +125,6 @@ void uv_process_getaddrinfo_req(uv_loop_t* loop, uv_getaddrinfo_t* handle, handle->alloc = NULL; } - uv_ret = uv_translate_eai_error(handle->retcode); if (handle->retcode == 0) { /* convert addrinfoW to addrinfo */ /* first calculate required length */ @@ -136,7 +135,8 @@ void uv_process_getaddrinfo_req(uv_loop_t* loop, uv_getaddrinfo_t* handle, if (addrinfow_ptr->ai_canonname != NULL) { name_len = uv_utf16_to_utf8(addrinfow_ptr->ai_canonname, -1, NULL, 0); if (name_len == 0) { - uv_ret = uv_translate_sys_error(GetLastError()); + uv__set_sys_error(loop, GetLastError()); + status = -1; goto complete; } addrinfo_len += ALIGNED_SIZE(name_len); @@ -201,9 +201,13 @@ void uv_process_getaddrinfo_req(uv_loop_t* loop, uv_getaddrinfo_t* handle, } } } else { - uv_ret = UV_ENOMEM; + uv__set_artificial_error(loop, UV_ENOMEM); + status = -1; } - + } else { + /* GetAddrInfo failed */ + uv__set_artificial_error(loop, uv_translate_eai_error(handle->retcode)); + status = -1; } /* return memory to system */ @@ -214,7 +218,7 @@ void uv_process_getaddrinfo_req(uv_loop_t* loop, uv_getaddrinfo_t* handle, complete: /* finally do callback with converted result */ - handle->getaddrinfo_cb(handle, uv_ret, (struct addrinfo*)alloc_ptr); + handle->getaddrinfo_cb(handle, status, (struct addrinfo*)alloc_ptr); uv_unref(loop); } diff --git a/src/win/udp.c b/src/win/udp.c index 07082ddb5..3beb8ab9e 100644 --- a/src/win/udp.c +++ b/src/win/udp.c @@ -466,17 +466,31 @@ void uv_process_udp_recv_req(uv_loop_t* loop, uv_udp_t* handle, handle->flags &= ~UV_HANDLE_READ_PENDING; - if (!REQ_SUCCESS(req) && - GET_REQ_SOCK_ERROR(req) != WSAEMSGSIZE) { - /* An error occurred doing the read. */ - if (handle->flags & UV_HANDLE_READING) { - uv__set_sys_error(loop, GET_REQ_SOCK_ERROR(req)); - uv_udp_recv_stop(handle); - buf = (handle->flags & UV_HANDLE_ZERO_READ) ? - uv_buf_init(NULL, 0) : handle->recv_buffer; - handle->recv_cb(handle, -1, buf, NULL, 0); + if (!REQ_SUCCESS(req)) { + DWORD err = GET_REQ_SOCK_ERROR(req); + if (err == WSAEMSGSIZE) { + /* Not a real error, it just indicates that the received packet */ + /* was bigger than the receive buffer. */ + } else if (err == WSAECONNRESET || err == WSAENETRESET) { + /* A previous sendto operation failed; ignore this error. If */ + /* zero-reading we need to call WSARecv/WSARecvFrom _without_ the */ + /* MSG_PEEK flag to clear out the error queue. For nonzero reads, */ + /* immediately queue a new receive. */ + if (!(handle->flags & UV_HANDLE_ZERO_READ)) { + goto done; + } + } else { + /* A real error occurred. Report the error to the user only if we're */ + /* currently reading. */ + if (handle->flags & UV_HANDLE_READING) { + uv__set_sys_error(loop, err); + uv_udp_recv_stop(handle); + buf = (handle->flags & UV_HANDLE_ZERO_READ) ? + uv_buf_init(NULL, 0) : handle->recv_buffer; + handle->recv_cb(handle, -1, buf, NULL, 0); + } + goto done; } - goto done; } if (!(handle->flags & UV_HANDLE_ZERO_READ)) { @@ -527,8 +541,10 @@ void uv_process_udp_recv_req(uv_loop_t* loop, uv_udp_t* handle, /* Kernel buffer empty */ uv__set_sys_error(loop, WSAEWOULDBLOCK); handle->recv_cb(handle, 0, buf, NULL, 0); - } else { - /* Ouch! serious error. */ + } else if (err != WSAECONNRESET && err != WSAENETRESET) { + /* Serious error. WSAECONNRESET/WSANETRESET is ignored because this */ + /* just indicates that a previous sendto operation failed. */ + uv_udp_recv_stop(handle); uv__set_sys_error(loop, err); handle->recv_cb(handle, -1, buf, NULL, 0); } diff --git a/src/win/winsock.c b/src/win/winsock.c index 5309f1eed..78acba909 100644 --- a/src/win/winsock.c +++ b/src/win/winsock.c @@ -144,6 +144,7 @@ int uv_ntstatus_to_winsock_error(NTSTATUS status) { case STATUS_LINK_FAILED: case STATUS_CONNECTION_DISCONNECTED: case STATUS_PORT_UNREACHABLE: + case STATUS_HOPLIMIT_EXCEEDED: return WSAECONNRESET; case STATUS_LOCAL_DISCONNECT: @@ -206,7 +207,8 @@ int uv_ntstatus_to_winsock_error(NTSTATUS status) { return WSAEACCES; default: - if (status & ((FACILITY_NTWIN32 << 16) | ERROR_SEVERITY_ERROR)) { + if ((status & (FACILITY_NTWIN32 << 16)) == (FACILITY_NTWIN32 << 16) && + (status & (ERROR_SEVERITY_ERROR | ERROR_SEVERITY_WARNING))) { /* It's a windows error that has been previously mapped to an */ /* ntstatus code. */ return (DWORD) (status & 0xffff);