| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -95,8 +95,12 @@ function setupChannel(target, channel) { | |||
| 95 | 95 | if (!target._channel) throw new Error("channel closed"); | |
| 96 | 96 | ||
| 97 | 97 | // 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) { | ||
| 99 | 100 | sendStream = sendStream._handle; | |
| 101 | + if (!sendStream) { | ||
| 102 | + throw new Error("sendStream handle not yet opened"); | ||
| 103 | + } | ||
| 100 | 104 | } | |
| 101 | 105 | ||
| 102 | 106 | // For overflow protection don't write if channel queue is too deep. | |
@@ -397,8 +401,6 @@ function setStreamOption(name, index, options) { | |||
| 397 | 401 | ChildProcess.prototype.spawn = function(options) { | |
| 398 | 402 | var self = this; | |
| 399 | 403 | ||
| 400 | - debugger; | ||
| 401 | - | ||
| 402 | 404 | setStreamOption('stdinStream', 0, options); | |
| 403 | 405 | setStreamOption('stdoutStream', 1, options); | |
| 404 | 406 | setStreamOption('stderrStream', 2, options); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -389,6 +389,12 @@ | |||
| 389 | 389 | var fd = parseInt(process.env.NODE_CHANNEL_FD); | |
| 390 | 390 | assert(fd >= 0); | |
| 391 | 391 | 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 | + | ||
| 392 | 398 | cp._forkChild(fd); | |
| 393 | 399 | assert(process.send); | |
| 394 | 400 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -183,8 +183,6 @@ void StreamWrap::OnReadCommon(uv_stream_t* handle, ssize_t nread, | |||
| 183 | 183 | uv_buf_t buf, uv_handle_type pending) { | |
| 184 | 184 | HandleScope scope; | |
| 185 | 185 | ||
| 186 | - assert(pending == UV_UNKNOWN_HANDLE); // TODO | ||
| 187 | - | ||
| 188 | 186 | StreamWrap* wrap = static_cast<StreamWrap*>(handle->data); | |
| 189 | 187 | ||
| 190 | 188 | // 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, | |||
| 220 | 218 | Integer::New(nread) | |
| 221 | 219 | }; | |
| 222 | 220 | ||
| 221 | + | ||
| 223 | 222 | if (pending == UV_TCP) { | |
| 224 | 223 | // Instantiate the client javascript object and handle. | |
| 225 | 224 | Local<Object> pending_obj = TCPWrap::Instantiate(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -56,8 +56,14 @@ typedef class ReqWrap<uv_connect_t> ConnectWrap; | |||
| 56 | 56 | ||
| 57 | 57 | ||
| 58 | 58 | 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 | + | ||
| 59 | 63 | HandleScope scope; | |
| 60 | - return scope.Close(tcpConstructor->NewInstance()); | ||
| 64 | + Local<Object> obj = tcpConstructor->NewInstance(); | ||
| 65 | + | ||
| 66 | + return scope.Close(obj); | ||
| 61 | 67 | } | |
| 62 | 68 | ||
| 63 | 69 | ||
| Original file line number | Diff line number | Diff 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 | + | ||
| Original file line number | Diff line number | Diff 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 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments