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

Commit

Permalink
windows: fixes crash in pipe.c
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Zinkovsky committed Oct 7, 2011
1 parent 81c09cb commit 9f6024a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
3 changes: 1 addition & 2 deletions 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 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 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 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 9f6024a

Please sign in to comment.