Skip to content

Commit a839aed

Browse files
sam-githubaddaleax
authored andcommitted
net: return this from getConnections()
PR-URL: #13553 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 69f806c commit a839aed

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

doc/api/net.md

+2
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ connections use asynchronous `server.getConnections` instead.
162162
added: v0.9.7
163163
-->
164164

165+
* Returns {net.Server}
166+
165167
Asynchronously get the number of concurrent connections on the server. Works
166168
when sockets were sent to forks.
167169

lib/net.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1558,7 +1558,8 @@ Server.prototype.getConnections = function(cb) {
15581558
}
15591559

15601560
if (!this._usingSlaves) {
1561-
return end(null, this._connections);
1561+
end(null, this._connections);
1562+
return this;
15621563
}
15631564

15641565
// Poll slaves
@@ -1578,6 +1579,8 @@ Server.prototype.getConnections = function(cb) {
15781579
for (var n = 0; n < this._slaves.length; n++) {
15791580
this._slaves[n].getConnections(oncount);
15801581
}
1582+
1583+
return this;
15811584
};
15821585

15831586

test/parallel/test-net-pingpong.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@ function pingPongTest(port, host) {
3737

3838
function onSocket(socket) {
3939
assert.strictEqual(socket.server, server);
40-
server.getConnections(common.mustCall(function(err, connections) {
41-
assert.ifError(err);
42-
assert.strictEqual(connections, 1);
43-
}));
40+
assert.strictEqual(
41+
server,
42+
server.getConnections(common.mustCall(function(err, connections) {
43+
assert.ifError(err);
44+
assert.strictEqual(connections, 1);
45+
}))
46+
);
4447

4548
socket.setNoDelay();
4649
socket.timeout = 0;

0 commit comments

Comments
 (0)