diff --git a/doc/api/net.md b/doc/api/net.md index 86c9159bcf..c66b87a261 100644 --- a/doc/api/net.md +++ b/doc/api/net.md @@ -162,6 +162,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. diff --git a/lib/net.js b/lib/net.js index 67c231ef25..1533843dba 100644 --- a/lib/net.js +++ b/lib/net.js @@ -1550,7 +1550,8 @@ Server.prototype.getConnections = function(cb) { } if (!this._usingSlaves) { - return end(null, this._connections); + end(null, this._connections); + return this; } // Poll slaves @@ -1570,6 +1571,8 @@ Server.prototype.getConnections = function(cb) { for (var n = 0; n < this._slaves.length; n++) { this._slaves[n].getConnections(oncount); } + + return this; }; diff --git a/test/parallel/test-net-pingpong.js b/test/parallel/test-net-pingpong.js index d030d069c6..c83cfaf943 100644 --- a/test/parallel/test-net-pingpong.js +++ b/test/parallel/test-net-pingpong.js @@ -37,10 +37,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;