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

Commit

Permalink
uv: float win pipe patch
Browse files Browse the repository at this point in the history
Float patch to fix pipe on Windows. Original commit message:

  win: fix pipe blocking writes

  In the code path for pipe blocking writes, WriteFile is already
  posting a completion packet to the I/O completion port.
  POST_COMPLETION_FOR_REQ was causing the same request to get
  returned twice by GetCompletionStatusEx.
  Also on the same code path, we were waiting on the wrong event.

  We need to update queued_bytes and write_queue_size when a
  blocking write request completes asynchronously.

Ref: libuv/libuv#238

Reviewed-By: Julien Gilli <julien.gilli@joyent.com>
PR-URL: #9179
  • Loading branch information
orangemocha authored and trevnorris committed Mar 19, 2015
1 parent 2411bea commit 3cce8ab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
12 changes: 6 additions & 6 deletions deps/uv/src/win/pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -1347,7 +1347,7 @@ static int uv_pipe_write_impl(uv_loop_t* loop,
}

/* Request queued by the kernel. */
req->queued_bytes = uv__count_bufs(bufs, nbufs);
req->queued_bytes = bufs[0].len;
handle->write_queue_size += req->queued_bytes;
} else if (handle->flags & UV_HANDLE_BLOCKING_WRITES) {
/* Using overlapped IO, but wait for completion before returning */
Expand All @@ -1372,12 +1372,13 @@ static int uv_pipe_write_impl(uv_loop_t* loop,
/* Request completed immediately. */
req->queued_bytes = 0;
} else {
assert(ipc_header_req != NULL);
/* Request queued by the kernel. */
if (WaitForSingleObject(ipc_header_req->overlapped.hEvent, INFINITE) !=
req->queued_bytes = bufs[0].len;
handle->write_queue_size += req->queued_bytes;
if (WaitForSingleObject(req->overlapped.hEvent, INFINITE) !=
WAIT_OBJECT_0) {
err = GetLastError();
CloseHandle(ipc_header_req->overlapped.hEvent);
CloseHandle(req->overlapped.hEvent);
return uv_translate_sys_error(err);
}
}
Expand All @@ -1386,7 +1387,6 @@ static int uv_pipe_write_impl(uv_loop_t* loop,
REGISTER_HANDLE_REQ(loop, handle, req);
handle->reqs_pending++;
handle->write_reqs_pending++;
POST_COMPLETION_FOR_REQ(loop, req);
return 0;
} else {
result = WriteFile(handle->handle,
Expand All @@ -1404,7 +1404,7 @@ static int uv_pipe_write_impl(uv_loop_t* loop,
req->queued_bytes = 0;
} else {
/* Request queued by the kernel. */
req->queued_bytes = uv__count_bufs(bufs, nbufs);
req->queued_bytes = bufs[0].len;
handle->write_queue_size += req->queued_bytes;
}

Expand Down
11 changes: 11 additions & 0 deletions deps/uv/src/win/req-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ INLINE static uv_req_t* uv_overlapped_to_req(OVERLAPPED* overlapped) {
INLINE static void uv_insert_pending_req(uv_loop_t* loop, uv_req_t* req) {
req->next_req = NULL;
if (loop->pending_reqs_tail) {
#ifdef _DEBUG
/* Ensure the request is not already in the queue, or the queue
* will get corrupted.
*/
uv_req_t* current = loop->pending_reqs_tail;
do {
assert(req != current);
current = current->next_req;
} while(current != loop->pending_reqs_tail);
#endif

req->next_req = loop->pending_reqs_tail->next_req;
loop->pending_reqs_tail->next_req = req;
loop->pending_reqs_tail = req;
Expand Down

0 comments on commit 3cce8ab

Please sign in to comment.