FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add test-child-process-fork2 and fixes to make it work · wave2future/node@899358e · GitHub

Repository navigation

Commit 899358e

Browse files
committed
Add test-child-process-fork2 and fixes to make it work
1 parent 4561d9e commit 899358e

6 files changed

Lines changed: 55 additions & 6 deletions

File tree

‎lib/child_process_uv.js‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,12 @@ function setupChannel(target, channel) {
9595
if (!target._channel) throw new Error("channel closed");
9696

9797
// Open up net.Socket instances
98-
if (sendStream instanceof require('net').Socket) {
98+
if (sendStream instanceof require('net').Socket ||
99+
sendStream instanceof require('net').Server) {
99100
sendStream = sendStream._handle;
101+
if (!sendStream) {
102+
throw new Error("sendStream handle not yet opened");
103+
}
100104
}
101105

102106
// For overflow protection don't write if channel queue is too deep.
@@ -397,8 +401,6 @@ function setStreamOption(name, index, options) {
397401
ChildProcess.prototype.spawn = function(options) {
398402
var self = this;
399403

400-
debugger;
401-
402404
setStreamOption('stdinStream', 0, options);
403405
setStreamOption('stdoutStream', 1, options);
404406
setStreamOption('stderrStream', 2, options);

‎src/node.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,12 @@
389389
var fd = parseInt(process.env.NODE_CHANNEL_FD);
390390
assert(fd >= 0);
391391
var cp = NativeModule.require('child_process');
392+
393+
// Load tcp_wrap to avoid situation where we might immediately receive
394+
// a message.
395+
// FIXME is this really necessary?
396+
process.binding('tcp_wrap')
397+
392398
cp._forkChild(fd);
393399
assert(process.send);
394400
}

‎src/stream_wrap.cc‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,6 @@ void StreamWrap::OnReadCommon(uv_stream_t* handle, ssize_t nread,
183183
uv_buf_t buf, uv_handle_type pending) {
184184
HandleScope scope;
185185

186-
assert(pending == UV_UNKNOWN_HANDLE); // TODO
187-
188186
StreamWrap* wrap = static_cast<StreamWrap*>(handle->data);
189187

190188
// We should not be getting this callback if someone as already called
@@ -220,6 +218,7 @@ void StreamWrap::OnReadCommon(uv_stream_t* handle, ssize_t nread,
220218
Integer::New(nread)
221219
};
222220

221+
223222
if (pending == UV_TCP) {
224223
// Instantiate the client javascript object and handle.
225224
Local<Object> pending_obj = TCPWrap::Instantiate();

‎src/tcp_wrap.cc‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,14 @@ typedef class ReqWrap<uv_connect_t> ConnectWrap;
5656

5757

5858
Local<Object> TCPWrap::Instantiate() {
59+
// If this assert fire then process.binding('tcp_wrap') hasn't been
60+
// called yet.
61+
assert(tcpConstructor.IsEmpty() == false);
62+
5963
HandleScope scope;
60-
return scope.Close(tcpConstructor->NewInstance());
64+
Local<Object> obj = tcpConstructor->NewInstance();
65+
66+
return scope.Close(obj);
6167
}
6268

6369

‎test/fixtures/fork2.js‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var assert = require('assert');
2+
3+
process.on('message', function(m, server) {
4+
console.log('CHILD got message:', m);
5+
assert.ok(m.hello);
6+
assert.ok(server);
7+
process.send({ gotHandle: true });
8+
});
9+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
var assert = require('assert');
2+
var common = require('../common');
3+
var fork = require('child_process').fork;
4+
var net = require('net');
5+
6+
var n = fork(common.fixturesDir + '/fork2.js');
7+
8+
var messageCount = 0;
9+
10+
var server = new net.Server();
11+
server.listen(common.PORT, function() {
12+
console.log('PARENT send child server handle');
13+
n.send({ hello: 'world' }, server);
14+
});
15+
16+
17+
n.on('message', function(m) {
18+
console.log('PARENT got message:', m);
19+
assert.ok(m.gotHandle);
20+
messageCount++;
21+
n.kill();
22+
server.close();
23+
});
24+
25+
process.on('exit', function() {
26+
assert.equal(1, messageCount);
27+
});

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL