initial pass at lib/child_process_uv.js

This commit is contained in:
Ryan Dahl 2011-07-31 15:58:10 -07:00
parent d3d8f1b972
commit 7772f21b60
6 changed files with 31 additions and 6 deletions

View File

@ -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)

View File

@ -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;

View File

@ -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';

View File

@ -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;

View File

@ -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;
}