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

Commit

Permalink
windows: enable pending accepts knob
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Zinkovsky committed Nov 1, 2011
1 parent 21b64dc commit 3060266
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/child_process.js
Expand Up @@ -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);

Expand Down Expand Up @@ -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) {
Expand Down
21 changes: 21 additions & 0 deletions src/tcp_wrap.cc
Expand Up @@ -100,6 +100,10 @@ void TCPWrap::Initialize(Handle<Object> 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<Function>::New(t->GetFunction());

family_symbol = NODE_PSYMBOL("family");
Expand Down Expand Up @@ -251,6 +255,23 @@ Handle<Value> TCPWrap::SetKeepAlive(const Arguments& args) {
}


#ifdef _WIN32
Handle<Value> 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<Value> TCPWrap::Bind(const Arguments& args) {
HandleScope scope;

Expand Down
4 changes: 4 additions & 0 deletions src/tcp_wrap.h
Expand Up @@ -26,6 +26,10 @@ class TCPWrap : public StreamWrap {
static v8::Handle<v8::Value> Connect6(const v8::Arguments& args);
static v8::Handle<v8::Value> Open(const v8::Arguments& args);

#ifdef _WIN32
static v8::Handle<v8::Value> SetSimultaneousAccepts(const v8::Arguments& args);
#endif

static void OnConnection(uv_stream_t* handle, int status);
static void AfterConnect(uv_connect_t* req, int status);

Expand Down

0 comments on commit 3060266

Please sign in to comment.