Skip to content

Commit

Permalink
net: return this from getConnections()
Browse files Browse the repository at this point in the history
PR-URL: #13553
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
sam-github authored and MylesBorins committed Feb 13, 2018
1 parent 063c4fa commit 6a27774
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions doc/api/net.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ connections use asynchronous `server.getConnections` instead.
added: v0.9.7
-->

* Returns {net.Server}

Asynchronously get the number of concurrent connections on the server. Works
when sockets were sent to forks.

Expand Down
5 changes: 4 additions & 1 deletion lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -1487,7 +1487,8 @@ Server.prototype.getConnections = function(cb) {
}

if (!this._usingSlaves) {
return end(null, this._connections);
end(null, this._connections);
return this;
}

// Poll slaves
Expand All @@ -1507,6 +1508,8 @@ Server.prototype.getConnections = function(cb) {
this._slaves.forEach(function(slave) {
slave.getConnections(oncount);
});

return this;
};


Expand Down
11 changes: 7 additions & 4 deletions test/parallel/test-net-pingpong.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ function pingPongTest(port, host) {

function onSocket(socket) {
assert.strictEqual(socket.server, server);
server.getConnections(common.mustCall(function(err, connections) {
assert.ifError(err);
assert.strictEqual(connections, 1);
}));
assert.strictEqual(
server,
server.getConnections(common.mustCall(function(err, connections) {
assert.ifError(err);
assert.strictEqual(connections, 1);
}))
);

socket.setNoDelay();
socket.timeout = 0;
Expand Down

0 comments on commit 6a27774

Please sign in to comment.