diff --git a/lib/child_process.js b/lib/child_process.js index 6e9b689fb00..48120866060 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -69,11 +69,29 @@ function mergeOptions(target, overrides) { function setupChannel(target, channel) { + var isWindows = process.platform === 'win32'; target._channel = channel; var jsonBuffer = ''; + if (isWindows) { + var setSimultaneousAccepts = function(handle) { + var simultaneousAccepts = (process.env.NODE_MANY_ACCEPTS + && process.env.NODE_MANY_ACCEPTS != '0') ? true : false; + + if (handle._simultaneousAccepts != simultaneousAccepts) { + handle.setSimultaneousAccepts(simultaneousAccepts); + handle._simultaneousAccepts = simultaneousAccepts; + } + } + } + channel.onread = function(pool, offset, length, recvHandle) { + if (recvHandle && setSimultaneousAccepts) { + // Update simultaneous accepts on Windows + setSimultaneousAccepts(recvHandle); + } + if (pool) { jsonBuffer += pool.toString('ascii', offset, offset + length); @@ -103,6 +121,11 @@ function setupChannel(target, channel) { var buffer = Buffer(JSON.stringify(message) + '\n'); + if (sendHandle && setSimultaneousAccepts) { + // Update simultaneous accepts on Windows + setSimultaneousAccepts(sendHandle); + } + var writeReq = channel.write(buffer, 0, buffer.length, sendHandle); if (!writeReq) { diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index e676d048bd5..ab7a46e2bd1 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -100,6 +100,10 @@ void TCPWrap::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(t, "setNoDelay", SetNoDelay); NODE_SET_PROTOTYPE_METHOD(t, "setKeepAlive", SetKeepAlive); +#ifdef _WIN32 + NODE_SET_PROTOTYPE_METHOD(t, "setSimultaneousAccepts", SetSimultaneousAccepts); +#endif + tcpConstructor = Persistent::New(t->GetFunction()); family_symbol = NODE_PSYMBOL("family"); @@ -251,6 +255,23 @@ Handle TCPWrap::SetKeepAlive(const Arguments& args) { } +#ifdef _WIN32 +Handle TCPWrap::SetSimultaneousAccepts(const Arguments& args) { + HandleScope scope; + + UNWRAP + + bool enable = args[0]->BooleanValue(); + + int r = uv_tcp_simultaneous_accepts(&wrap->handle_, enable ? 1 : 0); + if (r) + SetErrno(uv_last_error(uv_default_loop())); + + return Undefined(); +} +#endif + + Handle TCPWrap::Bind(const Arguments& args) { HandleScope scope; diff --git a/src/tcp_wrap.h b/src/tcp_wrap.h index 4a52217a1a6..744fcba4efa 100644 --- a/src/tcp_wrap.h +++ b/src/tcp_wrap.h @@ -26,6 +26,10 @@ class TCPWrap : public StreamWrap { static v8::Handle Connect6(const v8::Arguments& args); static v8::Handle Open(const v8::Arguments& args); +#ifdef _WIN32 + static v8::Handle SetSimultaneousAccepts(const v8::Arguments& args); +#endif + static void OnConnection(uv_stream_t* handle, int status); static void AfterConnect(uv_connect_t* req, int status);