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

Commit

Permalink
Merge pull request #44 from JuliaLang/sf/win_pipe
Browse files Browse the repository at this point in the history
Fix windows pipes
  • Loading branch information
staticfloat authored Jun 25, 2017
2 parents 52d72a5 + f457c09 commit c5a4e58
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/win/pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,7 @@ static void uv_pipe_queue_read(uv_loop_t* loop, uv_pipe_t* handle) {
} else {
memset(&req->u.io.overlapped, 0, sizeof(req->u.io.overlapped));
if (handle->flags & UV_HANDLE_EMULATE_IOCP) {
assert(req->event_handle);
req->u.io.overlapped.hEvent = (HANDLE) ((uintptr_t) req->event_handle | 1);
}

Expand Down Expand Up @@ -1317,8 +1318,16 @@ int uv_pipe_read_start(uv_pipe_t* handle,

/* If reading was stopped and then started again, there could still be a */
/* read request pending. */
if (!(handle->flags & UV_HANDLE_READ_PENDING))
if (!(handle->flags & UV_HANDLE_READ_PENDING)) {
if (handle->flags & UV_HANDLE_EMULATE_IOCP &&
!handle->read_req.event_handle) {
handle->read_req.event_handle = CreateEvent(NULL, 0, 0, NULL);
if (!handle->read_req.event_handle) {
uv_fatal_error(GetLastError(), "CreateEvent");
}
}
uv_pipe_queue_read(loop, handle);
}

return 0;
}
Expand Down Expand Up @@ -1405,7 +1414,16 @@ static int uv_pipe_write_impl(uv_loop_t* loop,
req->ipc_header = 0;
req->event_handle = NULL;
req->wait_handle = INVALID_HANDLE_VALUE;

/* Prepare the overlapped structure. */
memset(&req->u.io.overlapped, 0, sizeof(req->u.io.overlapped));
if (handle->flags & (UV_HANDLE_EMULATE_IOCP | UV_HANDLE_BLOCKING_WRITES)) {
req->event_handle = CreateEvent(NULL, 0, 0, NULL);
if (!req->event_handle) {
uv_fatal_error(GetLastError(), "CreateEvent");
}
req->u.io.overlapped.hEvent = (HANDLE) ((uintptr_t) req->event_handle | 1);
}

if (handle->flags&UV_HANDLE_PIPE_IPC) {
assert(!(handle->flags & UV_HANDLE_NON_OVERLAPPED_PIPE));
Expand Down Expand Up @@ -1548,11 +1566,6 @@ static int uv_pipe_write_impl(uv_loop_t* loop,
handle->write_queue_size += req->u.io.queued_bytes;
} else if (handle->flags & UV_HANDLE_BLOCKING_WRITES) {
/* Using overlapped IO, but wait for completion before returning */
req->u.io.overlapped.hEvent = CreateEvent(NULL, 1, 0, NULL);
if (!req->u.io.overlapped.hEvent) {
uv_fatal_error(GetLastError(), "CreateEvent");
}

result = WriteFile(handle->handle,
bufs[0].base,
bufs[0].len,
Expand Down Expand Up @@ -1606,10 +1619,6 @@ static int uv_pipe_write_impl(uv_loop_t* loop,
}

if (handle->flags & UV_HANDLE_EMULATE_IOCP) {
req->event_handle = CreateEvent(NULL, 0, 0, NULL);
if (!req->event_handle) {
uv_fatal_error(GetLastError(), "CreateEvent");
}
if (!RegisterWaitForSingleObject(&req->wait_handle,
req->u.io.overlapped.hEvent, post_completion_write_wait, (void*) req,
INFINITE, WT_EXECUTEINWAITTHREAD)) {
Expand Down

0 comments on commit c5a4e58

Please sign in to comment.