ext/libuv/src/win/pipe.c in libuv-0.10.2 vs ext/libuv/src/win/pipe.c in libuv-0.10.3
- old
+ new
@@ -68,11 +68,11 @@
static void eof_timer_destroy(uv_pipe_t* pipe);
static void eof_timer_close_cb(uv_handle_t* handle);
static void uv_unique_pipe_name(char* ptr, char* name, size_t size) {
- _snprintf(name, size, "\\\\.\\pipe\\uv\\%p-%d", ptr, GetCurrentProcessId());
+ _snprintf(name, size, "\\\\.\\pipe\\uv\\%p-%u", ptr, GetCurrentProcessId());
}
int uv_pipe_init(uv_loop_t* loop, uv_pipe_t* handle, int ipc) {
uv_stream_init(loop, (uv_stream_t*)handle, UV_NAMED_PIPE);
@@ -1028,20 +1028,24 @@
}
}
}
-static int uv_pipe_write_impl(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) {
+static int uv_pipe_write_impl(uv_loop_t* loop,
+ uv_write_t* req,
+ uv_pipe_t* handle,
+ const uv_buf_t bufs[],
+ unsigned int nbufs,
+ uv_stream_t* send_handle,
+ uv_write_cb cb) {
int err;
int result;
uv_tcp_t* tcp_send_handle;
uv_write_t* ipc_header_req;
uv_ipc_frame_uv_stream ipc_frame;
- if (bufcnt != 1 && (bufcnt != 0 || !send_handle)) {
+ if (nbufs != 1 && (nbufs != 0 || !send_handle)) {
return ERROR_NOT_SUPPORTED;
}
/* Only TCP handles are supported for sharing. */
if (send_handle && ((send_handle->type != UV_TCP) ||
@@ -1079,11 +1083,11 @@
if (tcp_send_handle->flags & UV_HANDLE_CONNECTION) {
ipc_frame.header.flags |= UV_IPC_TCP_CONNECTION;
}
}
- if (bufcnt == 1) {
+ if (nbufs == 1) {
ipc_frame.header.flags |= UV_IPC_RAW_DATA;
ipc_frame.header.raw_data_length = bufs[0].len;
}
/*
@@ -1187,11 +1191,11 @@
if (handle->write_reqs_pending == 0) {
uv_queue_non_overlapped_write(handle);
}
/* Request queued by the kernel. */
- req->queued_bytes = uv_count_bufs(bufs, bufcnt);
+ req->queued_bytes = uv_count_bufs(bufs, nbufs);
handle->write_queue_size += req->queued_bytes;
} else if (handle->flags & UV_HANDLE_BLOCKING_WRITES) {
/* Using overlapped IO, but wait for completion before returning */
req->overlapped.hEvent = CreateEvent(NULL, 1, 0, NULL);
if (!req->overlapped.hEvent) {
@@ -1243,11 +1247,11 @@
if (result) {
/* Request completed immediately. */
req->queued_bytes = 0;
} else {
/* Request queued by the kernel. */
- req->queued_bytes = uv_count_bufs(bufs, bufcnt);
+ req->queued_bytes = uv_count_bufs(bufs, nbufs);
handle->write_queue_size += req->queued_bytes;
}
if (handle->flags & UV_HANDLE_EMULATE_IOCP) {
req->event_handle = CreateEvent(NULL, 0, 0, NULL);
@@ -1268,23 +1272,32 @@
return 0;
}
-int uv_pipe_write(uv_loop_t* loop, uv_write_t* req, uv_pipe_t* handle,
- uv_buf_t bufs[], int bufcnt, uv_write_cb cb) {
- return uv_pipe_write_impl(loop, req, handle, bufs, bufcnt, NULL, cb);
+int uv_pipe_write(uv_loop_t* loop,
+ uv_write_t* req,
+ uv_pipe_t* handle,
+ const uv_buf_t bufs[],
+ unsigned int nbufs,
+ uv_write_cb cb) {
+ return uv_pipe_write_impl(loop, req, handle, bufs, nbufs, NULL, cb);
}
-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) {
+int uv_pipe_write2(uv_loop_t* loop,
+ uv_write_t* req,
+ uv_pipe_t* handle,
+ const uv_buf_t bufs[],
+ unsigned int nbufs,
+ uv_stream_t* send_handle,
+ uv_write_cb cb) {
if (!handle->ipc) {
return WSAEINVAL;
}
- return uv_pipe_write_impl(loop, req, handle, bufs, bufcnt, send_handle, cb);
+ return uv_pipe_write_impl(loop, req, handle, bufs, nbufs, send_handle, cb);
}
static void uv_pipe_read_eof(uv_loop_t* loop, uv_pipe_t* handle,
uv_buf_t buf) {
@@ -1294,13 +1307,13 @@
handle->flags &= ~UV_HANDLE_READABLE;
uv_read_stop((uv_stream_t*) handle);
if (handle->read2_cb) {
- handle->read2_cb(handle, UV_EOF, uv_null_buf_, UV_UNKNOWN_HANDLE);
+ handle->read2_cb(handle, UV_EOF, &uv_null_buf_, UV_UNKNOWN_HANDLE);
} else {
- handle->read_cb((uv_stream_t*) handle, UV_EOF, uv_null_buf_);
+ handle->read_cb((uv_stream_t*) handle, UV_EOF, &uv_null_buf_);
}
}
static void uv_pipe_read_error(uv_loop_t* loop, uv_pipe_t* handle, int error,
@@ -1312,14 +1325,14 @@
uv_read_stop((uv_stream_t*) handle);
if (handle->read2_cb) {
handle->read2_cb(handle,
uv_translate_sys_error(error),
- buf,
+ &buf,
UV_UNKNOWN_HANDLE);
} else {
- handle->read_cb((uv_stream_t*)handle, uv_translate_sys_error(error), buf);
+ handle->read_cb((uv_stream_t*)handle, uv_translate_sys_error(error), &buf);
}
}
static void uv_pipe_read_error_or_eof(uv_loop_t* loop, uv_pipe_t* handle,
@@ -1427,16 +1440,16 @@
} else {
avail = min(avail, (DWORD)handle->remaining_ipc_rawdata_bytes);
}
}
- buf = handle->alloc_cb((uv_handle_t*) handle, avail);
+ handle->alloc_cb((uv_handle_t*) handle, avail, &buf);
if (buf.len == 0) {
if (handle->read2_cb) {
- handle->read2_cb(handle, UV_ENOBUFS, buf, UV_UNKNOWN_HANDLE);
+ handle->read2_cb(handle, UV_ENOBUFS, &buf, UV_UNKNOWN_HANDLE);
} else if (handle->read_cb) {
- handle->read_cb((uv_stream_t*) handle, UV_ENOBUFS, buf);
+ handle->read_cb((uv_stream_t*) handle, UV_ENOBUFS, &buf);
}
break;
}
assert(buf.base != NULL);
@@ -1449,22 +1462,22 @@
if (handle->ipc) {
assert(handle->remaining_ipc_rawdata_bytes >= bytes);
handle->remaining_ipc_rawdata_bytes =
handle->remaining_ipc_rawdata_bytes - bytes;
if (handle->read2_cb) {
- handle->read2_cb(handle, bytes, buf,
+ handle->read2_cb(handle, bytes, &buf,
handle->pending_ipc_info.socket_info ? UV_TCP : UV_UNKNOWN_HANDLE);
} else if (handle->read_cb) {
- handle->read_cb((uv_stream_t*)handle, bytes, buf);
+ handle->read_cb((uv_stream_t*)handle, bytes, &buf);
}
if (handle->pending_ipc_info.socket_info) {
free(handle->pending_ipc_info.socket_info);
handle->pending_ipc_info.socket_info = NULL;
}
} else {
- handle->read_cb((uv_stream_t*)handle, bytes, buf);
+ handle->read_cb((uv_stream_t*)handle, bytes, &buf);
}
/* Read again only if bytes == buf.len */
if (bytes <= buf.len) {
break;
@@ -1592,19 +1605,25 @@
uv_shutdown_t* req) {
assert(handle->type == UV_NAMED_PIPE);
UNREGISTER_HANDLE_REQ(loop, handle, req);
- /* Initialize and optionally start the eof timer. */
- /* This makes no sense if we've already seen EOF. */
if (handle->flags & UV_HANDLE_READABLE) {
+ /* Initialize and optionally start the eof timer. Only do this if the */
+ /* pipe is readable and we haven't seen EOF come in ourselves. */
eof_timer_init(handle);
/* If reading start the timer right now. */
/* Otherwise uv_pipe_queue_read will start it. */
if (handle->flags & UV_HANDLE_READ_PENDING) {
eof_timer_start(handle);
}
+
+ } else {
+ /* This pipe is not readable. We can just close it to let the other end */
+ /* know that we're done writing. */
+ CloseHandle(handle->handle);
+ handle->handle = INVALID_HANDLE_VALUE;
}
if (req->cb) {
req->cb(req, 0);
}