diff --git a/Makefile b/Makefile index 7e7f4bd7331..5dbcdd1a00d 100644 --- a/Makefile +++ b/Makefile @@ -233,6 +233,10 @@ UVTEST += simple/test-tls-request-timeout #UVTEST += simple/test-tls-server-verify # broken UVTEST += simple/test-tls-set-encoding +# child_process +UVTEST += simple/test-child-process-exit-code.js +UVTEST += simple/test-child-process-buffering.js + test-uv: all NODE_USE_UV=1 python tools/test.py $(UVTEST) diff --git a/lib/child_process.js b/lib/child_process_legacy.js similarity index 100% rename from lib/child_process.js rename to lib/child_process_legacy.js diff --git a/lib/net_uv.js b/lib/net_uv.js index aee816fe6ce..a8c339c248b 100644 --- a/lib/net_uv.js +++ b/lib/net_uv.js @@ -3,8 +3,19 @@ var stream = require('stream'); var timers = require('timers'); var util = require('util'); var assert = require('assert'); -var TCP = process.binding('tcp_wrap').TCP; -var Pipe = process.binding('pipe_wrap').Pipe; + +// constructor for lazy loading +function createPipe() { + var Pipe = process.binding('pipe_wrap').Pipe; + return new Pipe(); +} + +// constructor for lazy loading +function createTCP() { + var TCP = process.binding('tcp_wrap').TCP; + return new TCP(); +} + /* Bit flags for socket._flags */ var FLAG_GOT_EOF = 1 << 0; @@ -35,7 +46,7 @@ exports.connect = exports.createConnection = function(port /* [host], [cb] */) { var s; if (isPipeName(port)) { - s = new Socket({handle:new Pipe}); + s = new Socket({ handle: createPipe() }); } else { s = new Socket(); } @@ -411,7 +422,7 @@ Socket.prototype.connect = function(port /* [host], [cb] */) { var pipe = isPipeName(port); if (this.destroyed || !this._handle) { - this._handle = pipe ? new Pipe() : new TCP(); + this._handle = pipe ? createPipe() : createTCP(); initSocketHandle(this); } @@ -544,7 +555,8 @@ function listen(self, address, port, addressType) { if (!self._handle) { // assign handle in listen, and clean up if bind or listen fails - self._handle = (port == -1 && addressType == -1) ? new Pipe : new TCP; + self._handle = + (port == -1 && addressType == -1) ? createPipe() : createTCP(); } self._handle.socket = self; diff --git a/src/node.js b/src/node.js index 86768876980..ab9ee171dff 100644 --- a/src/node.js +++ b/src/node.js @@ -411,6 +411,10 @@ case 'net': return process.features.uv ? 'net_uv' : 'net_legacy'; + case 'child_process': + return process.features.uv ? 'child_process_uv' : + 'child_process_legacy'; + case 'timers': return process.features.uv ? 'timers_uv' : 'timers_legacy'; diff --git a/src/process_wrap.cc b/src/process_wrap.cc index 4b0f90a855b..6d9a230a9c0 100644 --- a/src/process_wrap.cc +++ b/src/process_wrap.cc @@ -149,6 +149,8 @@ class ProcessWrap : public HandleWrap { wrap->SetHandle((uv_handle_t*)&wrap->process_); assert(wrap->process_.data == wrap); + wrap->object_->Set(String::New("pid"), Integer::New(wrap->process_.pid)); + if (options.args) { for (int i = 0; options.args[i]; i++) free(options.args[i]); delete [] options.args; diff --git a/test/simple/test-process-wrap.js b/test/simple/test-process-wrap.js index 70c1e43fce1..b52f3fcbc4e 100644 --- a/test/simple/test-process-wrap.js +++ b/test/simple/test-process-wrap.js @@ -30,11 +30,14 @@ var processExited = false; var gotPipeEOF = false; var gotPipeData = false; -p.onexit = function() { +p.onexit = function(exitCode, signal) { console.log("exit"); p.close(); pipe.readStart(); + assert.equal(0, exitCode); + assert.equal(0, signal); + processExited = true; }