Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
Merge branch 'v0.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Nov 25, 2011
2 parents ef811b1 + 01f64f6 commit 35fa2a6
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 24 deletions.
1 change: 0 additions & 1 deletion include/uv.h
Expand Up @@ -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, "") \
Expand Down
1 change: 1 addition & 0 deletions src/win/error.c
Expand Up @@ -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;
Expand Down
28 changes: 25 additions & 3 deletions src/win/fs.c
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down
18 changes: 11 additions & 7 deletions src/win/getaddrinfo.c
Expand Up @@ -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;
Expand Down Expand Up @@ -117,15 +117,14 @@ 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) {
free(handle->alloc);
handle->alloc = NULL;
}

uv_ret = uv_translate_eai_error(handle->retcode);
if (handle->retcode == 0) {
/* convert addrinfoW to addrinfo */
/* first calculate required length */
Expand All @@ -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);
Expand Down Expand Up @@ -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 */
Expand All @@ -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);
}
Expand Down
40 changes: 28 additions & 12 deletions src/win/udp.c
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion src/win/winsock.c
Expand Up @@ -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:
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 35fa2a6

Please sign in to comment.