Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Upgrade libuv to 9f6024a
Fixes #1840
  • Loading branch information
ry committed Oct 7, 2011
1 parent 26c08a3 commit a23d8ad
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 40 deletions.
1 change: 1 addition & 0 deletions deps/uv/include/uv-private/uv-win.h
Expand Up @@ -300,6 +300,7 @@ RB_HEAD(uv_timer_tree_s, uv_timer_s);
int req_pending; \
uv_fs_event_cb cb; \
wchar_t* filew; \
wchar_t* short_filew; \
int is_path_dir; \
char* buffer;

Expand Down
8 changes: 6 additions & 2 deletions deps/uv/include/uv.h
Expand Up @@ -1063,7 +1063,11 @@ struct uv_fs_event_s {
};


/* Gets load avg */
/*
* Gets load avg
* See: http://en.wikipedia.org/wiki/Load_(computing)
* (Returns [0,0,0] for windows and cygwin)
*/
void uv_loadavg(double avg[3]);

/*
Expand All @@ -1087,7 +1091,7 @@ int uv_ip6_name(struct sockaddr_in6* src, char* dst, size_t size);
/* Gets the executable path */
int uv_exepath(char* buffer, size_t* size);

/* Memory info */
/* Gets memory info in bytes */
double uv_get_free_memory(void);
double uv_get_total_memory(void);

Expand Down
8 changes: 4 additions & 4 deletions deps/uv/src/unix/stream.c
Expand Up @@ -600,11 +600,11 @@ static void uv__read(uv_stream_t* stream) {
} else {
stream->read2_cb((uv_pipe_t*)stream, nread, buf, UV_UNKNOWN_HANDLE);
}
}

/* Return if we didn't fill the buffer, there is no more data to read. */
if (nread < buflen) {
return;
}
/* Return if we didn't fill the buffer, there is no more data to read. */
if (nread < buflen) {
return;
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions deps/uv/src/win/error.c
Expand Up @@ -105,6 +105,8 @@ uv_err_code uv_translate_sys_error(int sys_errno) {
case WSAECONNABORTED: return UV_ECONNABORTED;
case ERROR_CONNECTION_REFUSED: return UV_ECONNREFUSED;
case WSAECONNREFUSED: return UV_ECONNREFUSED;
case ERROR_NETNAME_DELETED: return UV_ECONNRESET;
case WSAECONNRESET: return UV_ECONNRESET;
case WSAEFAULT: return UV_EFAULT;
case ERROR_HOST_UNREACHABLE: return UV_EHOSTUNREACH;
case WSAEHOSTUNREACH: return UV_EHOSTUNREACH;
Expand Down
71 changes: 51 additions & 20 deletions deps/uv/src/win/fs-event.c
Expand Up @@ -41,7 +41,8 @@ static void uv_fs_event_init_handle(uv_loop_t* loop, uv_fs_event_t* handle,
handle->buffer = NULL;
handle->req_pending = 0;
handle->filew = NULL;

handle->short_filew = NULL;

uv_req_init(loop, (uv_req_t*)&handle->req);
handle->req.type = UV_FS_EVENT_REQ;
handle->req.data = (void*)handle;
Expand Down Expand Up @@ -95,25 +96,29 @@ static int uv_split_path(const wchar_t* filename, wchar_t** dir,
while (i > 0 && filename[--i] != '\\' && filename[i] != '/');

if (i == 0) {
*dir = (wchar_t*)malloc((MAX_PATH + 1) * sizeof(wchar_t));
if (!*dir) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
}

if (!GetCurrentDirectoryW(MAX_PATH, *dir)) {
free(*dir);
*dir = NULL;
return -1;
if (dir) {
*dir = (wchar_t*)malloc((MAX_PATH + 1) * sizeof(wchar_t));
if (!*dir) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
}

if (!GetCurrentDirectoryW(MAX_PATH, *dir)) {
free(*dir);
*dir = NULL;
return -1;
}
}

*file = wcsdup(filename);
} else {
*dir = (wchar_t*)malloc((i + 1) * sizeof(wchar_t));
if (!*dir) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
if (dir) {
*dir = (wchar_t*)malloc((i + 1) * sizeof(wchar_t));
if (!*dir) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
}
wcsncpy(*dir, filename, i);
(*dir)[i] = L'\0';
}
wcsncpy(*dir, filename, i);
(*dir)[i] = L'\0';

*file = (wchar_t*)malloc((len - i) * sizeof(wchar_t));
if (!*file) {
Expand All @@ -132,6 +137,7 @@ int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle,
int name_size;
DWORD attr, last_error;
wchar_t* dir = NULL, *dir_to_watch, *filenamew;
wchar_t short_path[MAX_PATH];

uv_fs_event_init_handle(loop, handle, filename, cb);

Expand Down Expand Up @@ -165,11 +171,23 @@ int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle,
* filename is a file. So we split filename into dir & file parts, and
* watch the dir directory.
*/

/* Convert to short path. */
if (!GetShortPathNameW(filenamew, short_path, COUNTOF(short_path))) {
last_error = GetLastError();
goto error;
}

if (uv_split_path(filenamew, &dir, &handle->filew) != 0) {
last_error = GetLastError();
goto error;
}

if (uv_split_path(short_path, NULL, &handle->short_filew) != 0) {
last_error = GetLastError();
goto error;
}

dir_to_watch = dir;
}

Expand All @@ -194,9 +212,9 @@ int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle,
}

if (CreateIoCompletionPort(handle->dir_handle,
loop->iocp,
(ULONG_PTR)handle,
0) == NULL) {
loop->iocp,
(ULONG_PTR)handle,
0) == NULL) {
last_error = GetLastError();
goto error;
}
Expand Down Expand Up @@ -242,6 +260,11 @@ int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle,
handle->filew = NULL;
}

if (handle->short_filew) {
free(handle->short_filew);
handle->short_filew = NULL;
}

if (handle->dir_handle != INVALID_HANDLE_VALUE) {
CloseHandle(handle->dir_handle);
handle->dir_handle = INVALID_HANDLE_VALUE;
Expand Down Expand Up @@ -279,8 +302,11 @@ void uv_process_fs_event_req(uv_loop_t* loop, uv_req_t* req,
* Fire the event only if we were asked to watch a directory,
* or if the filename filter matches.
*/
if (handle->is_path_dir || _wcsnicmp(handle->filew, file_info->FileName,
file_info->FileNameLength / sizeof(wchar_t)) == 0) {
if (handle->is_path_dir ||
_wcsnicmp(handle->filew, file_info->FileName,
file_info->FileNameLength / sizeof(wchar_t)) == 0 ||
_wcsnicmp(handle->short_filew, file_info->FileName,
file_info->FileNameLength / sizeof(wchar_t)) == 0) {

/* Convert the filename to utf8. */
utf8size = uv_utf16_to_utf8(file_info->FileName,
Expand Down Expand Up @@ -370,6 +396,11 @@ void uv_fs_event_endgame(uv_loop_t* loop, uv_fs_event_t* handle) {
handle->filew = NULL;
}

if (handle->short_filew) {
free(handle->short_filew);
handle->short_filew = NULL;
}

if (handle->filename) {
free(handle->filename);
handle->filename = NULL;
Expand Down
3 changes: 1 addition & 2 deletions deps/uv/src/win/internal.h
Expand Up @@ -64,8 +64,7 @@ void uv_process_timers(uv_loop_t* loop);
#define UV_HANDLE_SYNC_BYPASS_IOCP 0x20000
#define UV_HANDLE_ZERO_READ 0x40000
#define UV_HANDLE_TTY_RAW 0x80000
#define UV_HANDLE_USE_IPC_PROTOCOL 0x100000
#define UV_HANDLE_EMULATE_IOCP 0x200000
#define UV_HANDLE_EMULATE_IOCP 0x100000

void uv_want_endgame(uv_loop_t* loop, uv_handle_t* handle);
void uv_process_endgames(uv_loop_t* loop);
Expand Down
17 changes: 7 additions & 10 deletions deps/uv/src/win/pipe.c
Expand Up @@ -78,13 +78,10 @@ int uv_pipe_init(uv_loop_t* loop, uv_pipe_t* handle, int ipc) {
handle->ipc_pid = 0;
handle->remaining_ipc_rawdata_bytes = 0;
handle->pending_socket_info = NULL;
handle->ipc = ipc;

uv_req_init(loop, (uv_req_t*) &handle->ipc_header_write_req);

if (ipc) {
handle->flags |= UV_HANDLE_USE_IPC_PROTOCOL;
}

loop->counters.pipe_init++;

return 0;
Expand Down Expand Up @@ -585,7 +582,7 @@ int uv_pipe_accept(uv_pipe_t* server, uv_stream_t* client) {
uv_pipe_t* pipe_client;
uv_pipe_accept_t* req;

if (server->flags & UV_HANDLE_USE_IPC_PROTOCOL) {
if (server->ipc) {
if (!server->pending_socket_info) {
/* No valid pending sockets. */
uv__set_sys_error(loop, WSAEWOULDBLOCK);
Expand Down Expand Up @@ -780,7 +777,7 @@ static int uv_pipe_write_impl(uv_loop_t* loop, uv_write_t* req,
req->ipc_header = 0;
memset(&req->overlapped, 0, sizeof(req->overlapped));

if (handle->flags & UV_HANDLE_USE_IPC_PROTOCOL) {
if (handle->ipc) {
/* Use the IPC framing protocol. */
if (send_handle) {
tcp_send_handle = (uv_tcp_t*)send_handle;
Expand Down Expand Up @@ -892,7 +889,7 @@ int uv_pipe_write(uv_loop_t* loop, uv_write_t* req, uv_pipe_t* handle,

int uv_pipe_write2(uv_loop_t* loop, uv_write_t* req, uv_pipe_t* handle,
uv_buf_t bufs[], int bufcnt, uv_stream_t* send_handle, uv_write_cb cb) {
if (!(handle->flags & UV_HANDLE_USE_IPC_PROTOCOL)) {
if (!handle->ipc) {
uv__set_artificial_error(loop, UV_EINVAL);
return -1;
}
Expand Down Expand Up @@ -983,7 +980,7 @@ void uv_process_pipe_read_req(uv_loop_t* loop, uv_pipe_t* handle,
break;
}

if (handle->flags & UV_HANDLE_USE_IPC_PROTOCOL) {
if (handle->ipc) {
/* Use the IPC framing protocol to read the incoming data. */
if (handle->remaining_ipc_rawdata_bytes == 0) {
/* We're reading a new frame. First, read the header. */
Expand Down Expand Up @@ -1048,7 +1045,7 @@ void uv_process_pipe_read_req(uv_loop_t* loop, uv_pipe_t* handle,
&bytes,
NULL)) {
/* Successful read */
if (handle->flags & UV_HANDLE_USE_IPC_PROTOCOL) {
if (handle->ipc) {
assert(handle->remaining_ipc_rawdata_bytes >= bytes);
handle->remaining_ipc_rawdata_bytes =
handle->remaining_ipc_rawdata_bytes - bytes;
Expand Down Expand Up @@ -1280,7 +1277,7 @@ void uv_pipe_open(uv_pipe_t* pipe, uv_file file) {
HANDLE os_handle;

/* Special-case stdin with ipc. */
if (file == 0 && pipe->flags & UV_HANDLE_USE_IPC_PROTOCOL) {
if (file == 0 && pipe->ipc) {
os_handle = (HANDLE)_get_osfhandle(file);

if (os_handle == INVALID_HANDLE_VALUE ||
Expand Down
4 changes: 2 additions & 2 deletions deps/uv/src/win/process.c
Expand Up @@ -906,7 +906,7 @@ int uv_spawn(uv_loop_t* loop, uv_process_t* process,

/* Create stdio pipes. */
if (options.stdin_stream) {
if (options.stdin_stream->flags & UV_HANDLE_USE_IPC_PROTOCOL) {
if (options.stdin_stream->ipc) {
err = uv_create_stdio_pipe_pair(
loop,
options.stdin_stream,
Expand Down Expand Up @@ -985,7 +985,7 @@ int uv_spawn(uv_loop_t* loop, uv_process_t* process,
process->pid = info.dwProcessId;

if (options.stdin_stream &&
options.stdin_stream->flags & UV_HANDLE_USE_IPC_PROTOCOL) {
options.stdin_stream->ipc) {
options.stdin_stream->ipc_pid = info.dwProcessId;
}

Expand Down
1 change: 1 addition & 0 deletions deps/uv/test/test-ipc.c
Expand Up @@ -191,6 +191,7 @@ TEST_IMPL(ipc) {

r = uv_pipe_init(uv_default_loop(), &channel, 1);
ASSERT(r == 0);
ASSERT(channel.ipc);

memset(&options, 0, sizeof(uv_process_options_t));

Expand Down

0 comments on commit a23d8ad

Please sign in to comment.