From 35f25083d7bf6b1367c11b05f64ecf9caab00812 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 35e7abcee85cad..8e40c2297df77a 100644 --- a/doc/api/net.md +++ b/doc/api/net.md @@ -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. diff --git a/lib/net.js b/lib/net.js index 9cd648953eb25b..c819ac1516ebef 100644 --- a/lib/net.js +++ b/lib/net.js @@ -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 @@ -1507,6 +1508,8 @@ Server.prototype.getConnections = function(cb) { this._slaves.forEach(function(slave) { slave.getConnections(oncount); }); + + return this; }; diff --git a/test/parallel/test-net-pingpong.js b/test/parallel/test-net-pingpong.js index b2f756c1ba7147..1bcf5992124342 100644 --- a/test/parallel/test-net-pingpong.js +++ b/test/parallel/test-net-pingpong.js @@ -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;