Skip to content

Commit 75a19fb

Browse files
committed
net,child_process: improve naming in internal code
All of this code is internal-only, and the changed variables/methods are not generally useful to userland code. When backporting this to release branches, it might be appropriate to add non-enumerable aliases to be 100 % sure. PR-URL: #14449 Reviewed-By: Alexey Orlenko <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent e59987c commit 75a19fb

File tree

3 files changed

+63
-25
lines changed

3 files changed

+63
-25
lines changed

doc/api/deprecations.md

+11
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,17 @@ Type: Runtime
634634

635635
*Note*: change was made while `async_hooks` was an experimental API.
636636

637+
<a id="DEP00XX"></a>
638+
### DEP00XX: Several internal properties of net.Server
639+
640+
Type: Runtime
641+
642+
Accessing several internal, undocumented properties of `net.Server` instances
643+
with inappropriate names has been deprecated.
644+
645+
*Note*: As the original API was undocumented and not generally useful for
646+
non-internal code, no replacement API is provided.
647+
637648
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
638649
[`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array
639650
[`Buffer.from(buffer)`]: buffer.html#buffer_class_method_buffer_from_buffer

lib/internal/child_process.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,16 @@ const handleConversion = {
6363

6464
// if the socket was created by net.Server
6565
if (socket.server) {
66-
// the slave should keep track of the socket
66+
// the worker should keep track of the socket
6767
message.key = socket.server._connectionKey;
6868

6969
var firstTime = !this.channel.sockets.send[message.key];
7070
var socketList = getSocketList('send', this, message.key);
7171

7272
// the server should no longer expose a .connection property
7373
// and when asked to close it should query the socket status from
74-
// the slaves
75-
if (firstTime) socket.server._setupSlave(socketList);
74+
// the workers
75+
if (firstTime) socket.server._setupWorker(socketList);
7676

7777
// Act like socket is detached
7878
if (!options.keepOpen)
@@ -911,12 +911,12 @@ function _validateStdio(stdio, sync) {
911911
}
912912

913913

914-
function getSocketList(type, slave, key) {
915-
var sockets = slave.channel.sockets[type];
914+
function getSocketList(type, worker, key) {
915+
var sockets = worker.channel.sockets[type];
916916
var socketList = sockets[key];
917917
if (!socketList) {
918918
var Construct = type === 'send' ? SocketListSend : SocketListReceive;
919-
socketList = sockets[key] = new Construct(slave, key);
919+
socketList = sockets[key] = new Construct(worker, key);
920920
}
921921
return socketList;
922922
}
@@ -958,6 +958,5 @@ module.exports = {
958958
ChildProcess,
959959
setupChannel,
960960
_validateStdio,
961-
getSocketList,
962961
spawnSync
963962
};

lib/net.js

+46-18
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ function Server(options, connectionListener) {
11871187
Object.defineProperty(this, 'connections', {
11881188
get: internalUtil.deprecate(() => {
11891189

1190-
if (this._usingSlaves) {
1190+
if (this._usingWorkers) {
11911191
return null;
11921192
}
11931193
return this._connections;
@@ -1201,8 +1201,8 @@ function Server(options, connectionListener) {
12011201

12021202
this[async_id_symbol] = -1;
12031203
this._handle = null;
1204-
this._usingSlaves = false;
1205-
this._slaves = [];
1204+
this._usingWorkers = false;
1205+
this._workers = [];
12061206
this._unref = false;
12071207

12081208
this.allowHalfOpen = options.allowHalfOpen || false;
@@ -1555,13 +1555,13 @@ Server.prototype.getConnections = function(cb) {
15551555
nextTick(asyncId, cb, err, connections);
15561556
}
15571557

1558-
if (!this._usingSlaves) {
1558+
if (!this._usingWorkers) {
15591559
end(null, this._connections);
15601560
return this;
15611561
}
15621562

1563-
// Poll slaves
1564-
var left = this._slaves.length;
1563+
// Poll workers
1564+
var left = this._workers.length;
15651565
var total = this._connections;
15661566

15671567
function oncount(err, count) {
@@ -1574,8 +1574,8 @@ Server.prototype.getConnections = function(cb) {
15741574
if (--left === 0) return end(null, total);
15751575
}
15761576

1577-
for (var n = 0; n < this._slaves.length; n++) {
1578-
this._slaves[n].getConnections(oncount);
1577+
for (var n = 0; n < this._workers.length; n++) {
1578+
this._workers[n].getConnections(oncount);
15791579
}
15801580

15811581
return this;
@@ -1598,22 +1598,22 @@ Server.prototype.close = function(cb) {
15981598
this._handle = null;
15991599
}
16001600

1601-
if (this._usingSlaves) {
1602-
var left = this._slaves.length;
1603-
const onSlaveClose = () => {
1601+
if (this._usingWorkers) {
1602+
var left = this._workers.length;
1603+
const onWorkerClose = () => {
16041604
if (--left !== 0) return;
16051605

16061606
this._connections = 0;
16071607
this._emitCloseIfDrained();
16081608
};
16091609

16101610
// Increment connections to be sure that, even if all sockets will be closed
1611-
// during polling of slaves, `close` event will be emitted only once.
1611+
// during polling of workers, `close` event will be emitted only once.
16121612
this._connections++;
16131613

1614-
// Poll slaves
1615-
for (var n = 0; n < this._slaves.length; n++)
1616-
this._slaves[n].close(onSlaveClose);
1614+
// Poll workers
1615+
for (var n = 0; n < this._workers.length; n++)
1616+
this._workers[n].close(onWorkerClose);
16171617
} else {
16181618
this._emitCloseIfDrained();
16191619
}
@@ -1646,9 +1646,9 @@ Server.prototype.listenFD = internalUtil.deprecate(function(fd, type) {
16461646
}, 'Server.listenFD is deprecated. Use Server.listen({fd: <number>}) instead.',
16471647
'DEP0021');
16481648

1649-
Server.prototype._setupSlave = function(socketList) {
1650-
this._usingSlaves = true;
1651-
this._slaves.push(socketList);
1649+
Server.prototype._setupWorker = function(socketList) {
1650+
this._usingWorkers = true;
1651+
this._workers.push(socketList);
16521652
};
16531653

16541654
Server.prototype.ref = function() {
@@ -1693,6 +1693,34 @@ if (process.platform === 'win32') {
16931693
_setSimultaneousAccepts = function(handle) {};
16941694
}
16951695

1696+
// TODO(addaleax): Remove these after the Node 9.x branch cut.
1697+
Object.defineProperty(Server.prototype, '_usingSlaves', {
1698+
get: internalUtil.deprecate(function() {
1699+
return this._usingWorkers;
1700+
}, 'Accessing internal properties of net.Server is deprecated.', 'DEP00XX'),
1701+
set: internalUtil.deprecate((val) => {
1702+
this._usingWorkers = val;
1703+
}, 'Accessing internal properties of net.Server is deprecated.', 'DEP00XX'),
1704+
configurable: true, enumerable: false
1705+
});
1706+
1707+
Object.defineProperty(Server.prototype, '_slaves', {
1708+
get: internalUtil.deprecate(function() {
1709+
return this._workers;
1710+
}, 'Accessing internal properties of net.Server is deprecated.', 'DEP00XX'),
1711+
set: internalUtil.deprecate((val) => {
1712+
this._workers = val;
1713+
}, 'Accessing internal properties of net.Server is deprecated.', 'DEP00XX'),
1714+
configurable: true, enumerable: false
1715+
});
1716+
1717+
Object.defineProperty(Server.prototype, '_setupSlave', {
1718+
value: internalUtil.deprecate(function(socketList) {
1719+
return this._setupWorker(socketList);
1720+
}, 'Accessing internal properties of net.Server is deprecated.', 'DEP00XX'),
1721+
configurable: true, enumerable: false
1722+
});
1723+
16961724
module.exports = {
16971725
_createServerHandle: createServerHandle,
16981726
_normalizeArgs: normalizeArgs,

0 commit comments

Comments
 (0)