Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

windows: enable pending pipe instances knob

  • Loading branch information
Igor Zinkovsky
Igor Zinkovsky committed Dec 1, 2011
1 parent 9c064fb commit 60630dab0f336f5c611b9c76ddd37734a3a72270
Showing with 41 additions and 5 deletions.
  1. +2 −1 include/uv-private/uv-win.h
  2. +7 −0 include/uv.h
  3. +5 −0 src/unix/pipe.c
  4. +27 −4 src/win/pipe.c
@@ -276,7 +276,8 @@ RB_HEAD(uv_timer_tree_s, uv_timer_s);
LPFN_WSARECVFROM func_wsarecvfrom;

#define uv_pipe_server_fields \
uv_pipe_accept_t accept_reqs[4]; \
int pending_instances; \
uv_pipe_accept_t* accept_reqs; \
uv_pipe_accept_t* pending_accepts;

#define uv_pipe_connection_fields \
@@ -772,6 +772,13 @@ UV_EXTERN int uv_pipe_bind(uv_pipe_t* handle, const char* name);
UV_EXTERN void uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle,
const char* name, uv_connect_cb cb);

/*
* This setting applies to Windows only.
* Set the number of pending pipe instance handles when the pipe server
* is waiting for connections.
*/
UV_EXTERN void uv_pipe_pending_instances(uv_pipe_t* handle, int count);


/*
* uv_prepare_t is a subclass of uv_handle_t.
@@ -271,3 +271,8 @@ void uv__pipe_accept(EV_P_ ev_io* watcher, int revents) {

errno = saved_errno;
}


void uv_pipe_pending_instances(uv_pipe_t* handle, int count) {
return 0;
}
@@ -39,6 +39,8 @@ static const uv_buf_t uv_null_buf_ = { 0, NULL };
/* when the local ends wants to shut it down. */
static const int64_t eof_timeout = 50; /* ms */

static const int default_pending_pipe_instances = 4;

/* IPC protocol flags. */
#define UV_IPC_RAW_DATA 0x0001
#define UV_IPC_UV_STREAM 0x0002
@@ -293,6 +295,12 @@ void uv_pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle) {
}
}

if (handle->flags & UV_HANDLE_PIPESERVER) {
assert(handle->accept_reqs);
free(handle->accept_reqs);
handle->accept_reqs = NULL;
}

/* Remember the state of this flag because the close callback is */
/* allowed to clobber or free the handle's memory */
uv_alloced = handle->flags & UV_HANDLE_UV_ALLOCED;
@@ -310,6 +318,12 @@ void uv_pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle) {
}


void uv_pipe_pending_instances(uv_pipe_t* handle, int count) {
handle->pending_instances = count;
handle->flags |= UV_HANDLE_PIPESERVER;
}


/* Creates a pipe server. */
int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
uv_loop_t* loop = handle->loop;
@@ -326,7 +340,17 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
return -1;
}

for (i = 0; i < COUNTOF(handle->accept_reqs); i++) {
if (!(handle->flags & UV_HANDLE_PIPESERVER)) {
handle->pending_instances = default_pending_pipe_instances;
}

handle->accept_reqs = (uv_pipe_accept_t*)
malloc(sizeof(uv_pipe_accept_t) * handle->pending_instances);
if (!handle->accept_reqs) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
}

for (i = 0; i < handle->pending_instances; i++) {
req = &handle->accept_reqs[i];
uv_req_init(loop, (uv_req_t*) req);
req->type = UV_ACCEPT;
@@ -537,14 +561,13 @@ void close_pipe(uv_pipe_t* handle, int* status, uv_err_t* err) {
}

if (handle->flags & UV_HANDLE_PIPESERVER) {
for (i = 0; i < COUNTOF(handle->accept_reqs); i++) {
for (i = 0; i < handle->pending_instances; i++) {
pipeHandle = handle->accept_reqs[i].pipeHandle;
if (pipeHandle != INVALID_HANDLE_VALUE) {
CloseHandle(pipeHandle);
handle->accept_reqs[i].pipeHandle = INVALID_HANDLE_VALUE;
}
}

}

if (handle->flags & UV_HANDLE_CONNECTION) {
@@ -686,7 +709,7 @@ int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb) {
/* First pipe handle should have already been created in uv_pipe_bind */
assert(handle->accept_reqs[0].pipeHandle != INVALID_HANDLE_VALUE);

for (i = 0; i < COUNTOF(handle->accept_reqs); i++) {
for (i = 0; i < handle->pending_instances; i++) {
uv_pipe_queue_accept(loop, handle, &handle->accept_reqs[i], i == 0);
}

0 comments on commit 60630da

Please sign in to comment.
You can’t perform that action at this time.