From 7d4d59778aaa7ea0de7b248b0d4d372111886341 Mon Sep 17 00:00:00 2001 From: himself65 Date: Tue, 21 Apr 2020 19:24:29 +0800 Subject: [PATCH 1/5] lib: refactor Socket._getpeername and Socket._getsockname --- lib/net.js | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/lib/net.js b/lib/net.js index 1f105a179f2298..de5eed66c99015 100644 --- a/lib/net.js +++ b/lib/net.js @@ -669,14 +669,11 @@ Socket.prototype._destroy = function(exception, cb) { }; Socket.prototype._getpeername = function() { - if (!this._peername) { - if (!this._handle || !this._handle.getpeername) { - return {}; - } - const out = {}; - const err = this._handle.getpeername(out); - if (err) return {}; // FIXME(bnoordhuis) Throw? - this._peername = out; + if (!this._handle || !this._handle.getpeername) { + return {}; + } else if (!this._peername) { + // FIXME(bnoordhuis) Throws when returns not 0? + this._handle.getpeername(this._peername = {}); } return this._peername; }; @@ -709,12 +706,9 @@ protoGetter('remotePort', function remotePort() { Socket.prototype._getsockname = function() { if (!this._handle || !this._handle.getsockname) { return {}; - } - if (!this._sockname) { - const out = {}; - const err = this._handle.getsockname(out); - if (err) return {}; // FIXME(bnoordhuis) Throw? - this._sockname = out; + } else if (!this._sockname) { + // FIXME(bnoordhuis) Throws when returns not 0? + this._handle.getsockname(this._sockname = {}); } return this._sockname; }; From f61cae248aa0961a9400274c970f476003179184 Mon Sep 17 00:00:00 2001 From: himself65 Date: Sun, 24 May 2020 22:10:39 +0800 Subject: [PATCH 2/5] fixup! --- lib/net.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/net.js b/lib/net.js index de5eed66c99015..8d1315db310ee8 100644 --- a/lib/net.js +++ b/lib/net.js @@ -672,8 +672,9 @@ Socket.prototype._getpeername = function() { if (!this._handle || !this._handle.getpeername) { return {}; } else if (!this._peername) { + this._peername = {}; // FIXME(bnoordhuis) Throws when returns not 0? - this._handle.getpeername(this._peername = {}); + this._handle.getpeername(this._peername); } return this._peername; }; @@ -707,8 +708,9 @@ Socket.prototype._getsockname = function() { if (!this._handle || !this._handle.getsockname) { return {}; } else if (!this._sockname) { + this._sockname = {}; // FIXME(bnoordhuis) Throws when returns not 0? - this._handle.getsockname(this._sockname = {}); + this._handle.getsockname(this._sockname); } return this._sockname; }; From faa57e80e3351b8efd9f797a8f6ace14db21bea5 Mon Sep 17 00:00:00 2001 From: himself65 Date: Sun, 24 May 2020 23:21:32 +0800 Subject: [PATCH 3/5] fixup! backport --- lib/net.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/net.js b/lib/net.js index 8d1315db310ee8..a93e517f315d4a 100644 --- a/lib/net.js +++ b/lib/net.js @@ -670,7 +670,7 @@ Socket.prototype._destroy = function(exception, cb) { Socket.prototype._getpeername = function() { if (!this._handle || !this._handle.getpeername) { - return {}; + return this._peername || {}; } else if (!this._peername) { this._peername = {}; // FIXME(bnoordhuis) Throws when returns not 0? From 0156c9c7b03c865f649a9ea7c0af1e5762d829bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=A9=E6=95=A3=E6=80=A7=E7=99=BE=E4=B8=87=E7=94=9C?= =?UTF-8?q?=E9=9D=A2=E5=8C=85?= Date: Fri, 29 May 2020 17:43:24 +0800 Subject: [PATCH 4/5] fixup! Co-authored-by: Ben Noordhuis --- lib/net.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/net.js b/lib/net.js index a93e517f315d4a..e6dffa7770876a 100644 --- a/lib/net.js +++ b/lib/net.js @@ -673,7 +673,7 @@ Socket.prototype._getpeername = function() { return this._peername || {}; } else if (!this._peername) { this._peername = {}; - // FIXME(bnoordhuis) Throws when returns not 0? + // FIXME(bnoordhuis) Throw when the return value is not 0? this._handle.getpeername(this._peername); } return this._peername; From 8adc3364b2446b4f672abf217f766ef0dbe6b8de Mon Sep 17 00:00:00 2001 From: himself65 Date: Fri, 29 May 2020 17:46:16 +0800 Subject: [PATCH 5/5] fixup! edit comment --- lib/net.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/net.js b/lib/net.js index e6dffa7770876a..d40e61ea053c61 100644 --- a/lib/net.js +++ b/lib/net.js @@ -709,7 +709,7 @@ Socket.prototype._getsockname = function() { return {}; } else if (!this._sockname) { this._sockname = {}; - // FIXME(bnoordhuis) Throws when returns not 0? + // FIXME(bnoordhuis) Throw when the return value is not 0? this._handle.getsockname(this._sockname); } return this._sockname;