| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d4b5095 commit 7b0e937
8 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -776,6 +776,16 @@ added: v0.5.9 | |||
| 776 | 776 | The `'message'` event is triggered when a child process uses [`process.send()`][] | |
| 777 | 777 | to send messages. | |
| 778 | 778 | ||
| 779 | + ### child.channel | ||
| 780 | + <!-- YAML | ||
| 781 | + added: REPLACEME | ||
| 782 | + --> | ||
| 783 | + | ||
| 784 | + * {Object} A pipe representing the IPC channel to the child process. | ||
| 785 | + | ||
| 786 | + The `child.channel` property is a reference to the child's IPC channel. If no | ||
| 787 | + IPC channel currently exists, this property is `undefined`. | ||
| 788 | + | ||
| 779 | 789 | ### child.connected | |
| 780 | 790 | <!-- YAML | |
| 781 | 791 | added: v0.7.2 | |
@@ -1145,6 +1155,7 @@ console.log('中文测试'); | |||
| 1145 | 1155 | [`'error'`]: #child_process_event_error | |
| 1146 | 1156 | [`'exit'`]: #child_process_event_exit | |
| 1147 | 1157 | [`'message'`]: #child_process_event_message | |
| 1158 | + [`child.channel`]: #child_process_child_channel | ||
| 1148 | 1159 | [`child.connected`]: #child_process_child_connected | |
| 1149 | 1160 | [`child.disconnect()`]: #child_process_child_disconnect | |
| 1150 | 1161 | [`child.kill()`]: #child_process_child_kill_signal | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -508,6 +508,16 @@ $ bash -c 'exec -a customArgv0 ./node' | |||
| 508 | 508 | 'customArgv0' | |
| 509 | 509 | ``` | |
| 510 | 510 | ||
| 511 | + ## process.channel | ||
| 512 | + <!-- YAML | ||
| 513 | + added: REPLACEME | ||
| 514 | + --> | ||
| 515 | + | ||
| 516 | + If the Node.js process was spawned with an IPC channel (see the | ||
| 517 | + [Child Process][] documentation), the `process.channel` | ||
| 518 | + property is a reference to the IPC channel. If no IPC channel exists, this | ||
| 519 | + property is `undefined`. | ||
| 520 | + | ||
| 511 | 521 | ## process.chdir(directory) | |
| 512 | 522 | <!-- YAML | |
| 513 | 523 | added: v0.1.17 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -69,7 +69,7 @@ const handleConversion = { | |||
| 69 | 69 | // the slave should keep track of the socket | |
| 70 | 70 | message.key = socket.server._connectionKey; | |
| 71 | 71 | ||
| 72 | - var firstTime = !this._channel.sockets.send[message.key]; | ||
| 72 | + var firstTime = !this.channel.sockets.send[message.key]; | ||
| 73 | 73 | var socketList = getSocketList('send', this, message.key); | |
| 74 | 74 | ||
| 75 | 75 | // the server should no longer expose a .connection property | |
@@ -409,7 +409,15 @@ ChildProcess.prototype.unref = function() { | |||
| 409 | 409 | ||
| 410 | 410 | ||
| 411 | 411 | function setupChannel(target, channel) { | |
| 412 | - target._channel = channel; | ||
| 412 | + target.channel = channel; | ||
| 413 | + | ||
| 414 | + // _channel can be deprecated in version 8 | ||
| 415 | + Object.defineProperty(target, '_channel', { | ||
| 416 | + get() { return target.channel; }, | ||
| 417 | + set(val) { target.channel = val; }, | ||
| 418 | + enumerable: true | ||
| 419 | + }); | ||
| 420 | + | ||
| 413 | 421 | target._handleQueue = null; | |
| 414 | 422 | target._pendingHandle = null; | |
| 415 | 423 | ||
@@ -465,7 +473,7 @@ function setupChannel(target, channel) { | |||
| 465 | 473 | target.disconnect(); | |
| 466 | 474 | channel.onread = nop; | |
| 467 | 475 | channel.close(); | |
| 468 | - target._channel = null; | ||
| 476 | + target.channel = null; | ||
| 469 | 477 | maybeClose(target); | |
| 470 | 478 | } | |
| 471 | 479 | }; | |
@@ -491,7 +499,7 @@ function setupChannel(target, channel) { | |||
| 491 | 499 | }); | |
| 492 | 500 | ||
| 493 | 501 | // Process a pending disconnect (if any). | |
| 494 | - if (!target.connected && target._channel && !target._handleQueue) | ||
| 502 | + if (!target.connected && target.channel && !target._handleQueue) | ||
| 495 | 503 | target._disconnect(); | |
| 496 | 504 | ||
| 497 | 505 | return; | |
@@ -547,7 +555,7 @@ function setupChannel(target, channel) { | |||
| 547 | 555 | }; | |
| 548 | 556 | ||
| 549 | 557 | target._send = function(message, handle, options, callback) { | |
| 550 | - assert(this.connected || this._channel); | ||
| 558 | + assert(this.connected || this.channel); | ||
| 551 | 559 | ||
| 552 | 560 | if (message === undefined) | |
| 553 | 561 | throw new TypeError('"message" argument cannot be undefined'); | |
@@ -667,11 +675,11 @@ function setupChannel(target, channel) { | |||
| 667 | 675 | // connected will be set to false immediately when a disconnect() is | |
| 668 | 676 | // requested, even though the channel might still be alive internally to | |
| 669 | 677 | // process queued messages. The three states are distinguished as follows: | |
| 670 | - // - disconnect() never requested: _channel is not null and connected | ||
| 678 | + // - disconnect() never requested: channel is not null and connected | ||
| 671 | 679 | // is true | |
| 672 | - // - disconnect() requested, messages in the queue: _channel is not null | ||
| 680 | + // - disconnect() requested, messages in the queue: channel is not null | ||
| 673 | 681 | // and connected is false | |
| 674 | - // - disconnect() requested, channel actually disconnected: _channel is | ||
| 682 | + // - disconnect() requested, channel actually disconnected: channel is | ||
| 675 | 683 | // null and connected is false | |
| 676 | 684 | target.connected = true; | |
| 677 | 685 | ||
@@ -692,10 +700,10 @@ function setupChannel(target, channel) { | |||
| 692 | 700 | }; | |
| 693 | 701 | ||
| 694 | 702 | target._disconnect = function() { | |
| 695 | - assert(this._channel); | ||
| 703 | + assert(this.channel); | ||
| 696 | 704 | ||
| 697 | 705 | // This marks the fact that the channel is actually disconnected. | |
| 698 | - this._channel = null; | ||
| 706 | + this.channel = null; | ||
| 699 | 707 | ||
| 700 | 708 | if (this._pendingHandle) { | |
| 701 | 709 | this._pendingHandle.close(); | |
@@ -729,7 +737,7 @@ function setupChannel(target, channel) { | |||
| 729 | 737 | ||
| 730 | 738 | const INTERNAL_PREFIX = 'NODE_'; | |
| 731 | 739 | function handleMessage(target, message, handle) { | |
| 732 | - if (!target._channel) | ||
| 740 | + if (!target.channel) | ||
| 733 | 741 | return; | |
| 734 | 742 | ||
| 735 | 743 | var eventName = 'message'; | |
@@ -860,7 +868,7 @@ function _validateStdio(stdio, sync) { | |||
| 860 | 868 | ||
| 861 | 869 | ||
| 862 | 870 | function getSocketList(type, slave, key) { | |
| 863 | - var sockets = slave._channel.sockets[type]; | ||
| 871 | + var sockets = slave.channel.sockets[type]; | ||
| 864 | 872 | var socketList = sockets[key]; | |
| 865 | 873 | if (!socketList) { | |
| 866 | 874 | var Construct = type === 'send' ? SocketListSend : SocketListReceive; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -60,9 +60,9 @@ function setupStdio() { | |||
| 60 | 60 | // sitting on fd=0, in such case the pipe for this fd is already | |
| 61 | 61 | // present and creating a new one will lead to the assertion failure | |
| 62 | 62 | // in libuv. | |
| 63 | - if (process._channel && process._channel.fd === fd) { | ||
| 63 | + if (process.channel && process.channel.fd === fd) { | ||
| 64 | 64 | stdin = new net.Socket({ | |
| 65 | - handle: process._channel, | ||
| 65 | + handle: process.channel, | ||
| 66 | 66 | readable: true, | |
| 67 | 67 | writable: false | |
| 68 | 68 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,8 +44,8 @@ var server = net.createServer(function(s) { | |||
| 44 | 44 | } | |
| 45 | 45 | ||
| 46 | 46 | worker.process.once('close', common.mustCall(function() { | |
| 47 | - // Otherwise the crash on `_channel.fd` access may happen | ||
| 48 | - assert.strictEqual(worker.process._channel, null); | ||
| 47 | + // Otherwise the crash on `channel.fd` access may happen | ||
| 48 | + assert.strictEqual(worker.process.channel, null); | ||
| 49 | 49 | server.close(); | |
| 50 | 50 | })); | |
| 51 | 51 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,8 @@ var fork = require('child_process').fork; | |||
| 5 | 5 | var args = ['foo', 'bar']; | |
| 6 | 6 | ||
| 7 | 7 | var n = fork(common.fixturesDir + '/child-process-spawn-node.js', args); | |
| 8 | + | ||
| 9 | + assert.strictEqual(n.channel, n._channel); | ||
| 8 | 10 | assert.deepStrictEqual(args, ['foo', 'bar']); | |
| 9 | 11 | ||
| 10 | 12 | n.on('message', function(m) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,12 +36,12 @@ function master() { | |||
| 36 | 36 | } | |
| 37 | 37 | ||
| 38 | 38 | function worker() { | |
| 39 | - process._channel.readStop(); // Make messages batch up. | ||
| 39 | + process.channel.readStop(); // Make messages batch up. | ||
| 40 | 40 | process.stdout.ref(); | |
| 41 | 41 | process.stdout.write('ok\r\n'); | |
| 42 | 42 | process.stdin.once('data', common.mustCall((data) => { | |
| 43 | 43 | assert.strictEqual(data.toString(), 'ok\r\n'); | |
| 44 | - process._channel.readStart(); | ||
| 44 | + process.channel.readStart(); | ||
| 45 | 45 | })); | |
| 46 | 46 | let n = 0; | |
| 47 | 47 | process.on('message', common.mustCall((msg, handle) => { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,8 +21,8 @@ if (process.argv[2] === 'pipe') { | |||
| 21 | 21 | const child = childProcess.fork(process.argv[1], ['pipe'], {silent: true}); | |
| 22 | 22 | ||
| 23 | 23 | // Allow child process to self terminate | |
| 24 | - child._channel.close(); | ||
| 25 | - child._channel = null; | ||
| 24 | + child.channel.close(); | ||
| 25 | + child.channel = null; | ||
| 26 | 26 | ||
| 27 | 27 | child.on('exit', function() { | |
| 28 | 28 | process.exit(0); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments