From 16ba772cd98280eea830cc820904d94d8bc7db51 Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Wed, 7 Jun 2017 12:49:00 -0700 Subject: [PATCH] net: return this from getConnections() PR-URL: https://github.com/nodejs/node/pull/13553 Reviewed-By: Colin Ihrig Reviewed-By: Roman Reiss Reviewed-By: Luigi Pinca Reviewed-By: Gibson Fahnestock Reviewed-By: James M Snell --- doc/api/net.md | 2 ++ lib/net.js | 5 ++++- test/parallel/test-net-pingpong.js | 11 +++++++---- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/doc/api/net.md b/doc/api/net.md index 86c9159bcfbcab..c66b87a261152b 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 19f69aaaad73b8..278153d3bdffc7 100644 --- a/lib/net.js +++ b/lib/net.js @@ -1558,7 +1558,8 @@ Server.prototype.getConnections = function(cb) { } if (!this._usingSlaves) { - return end(null, this._connections); + end(null, this._connections); + return this; } // Poll slaves @@ -1578,6 +1579,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 d030d069c6d1d7..c83cfaf94349df 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;