diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-11-04 12:28:27 +0100 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-11-10 19:36:08 +0100 |
commit | b7e6ccd0cc60f20cc397e6ac0705bb3f38c7d225 (patch) | |
tree | b5726139d4645cec13cb3e172a5ee9153de1f474 /lib/net.js | |
parent | 9c6b7f7b1d1c64081c11f291409c67d66fc4f2af (diff) | |
download | android-node-v8-b7e6ccd0cc60f20cc397e6ac0705bb3f38c7d225.tar.gz android-node-v8-b7e6ccd0cc60f20cc397e6ac0705bb3f38c7d225.tar.bz2 android-node-v8-b7e6ccd0cc60f20cc397e6ac0705bb3f38c7d225.zip |
net: simplify Socket.prototype._final
Remove conditions that should be irrelevant since we started
using `_final`, as well as an extra `defaultTriggerAsyncIdScope()`
call which is unnecessary because there is an equivalent
scope already present on the native side.
PR-URL: https://github.com/nodejs/node/pull/24075
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/net.js')
-rw-r--r-- | lib/net.js | 31 |
1 files changed, 8 insertions, 23 deletions
diff --git a/lib/net.js b/lib/net.js index 05fc4fa959..5d332d9e1d 100644 --- a/lib/net.js +++ b/lib/net.js @@ -336,14 +336,6 @@ Socket.prototype._unrefTimer = function _unrefTimer() { }; -function shutdownSocket(self, callback) { - var req = new ShutdownWrap(); - req.oncomplete = afterShutdown; - req.handle = self._handle; - req.callback = callback; - return self._handle.shutdown(req); -} - // the user has called .end(), and all the bytes have been // sent out to the other side. Socket.prototype._final = function(cb) { @@ -353,23 +345,16 @@ Socket.prototype._final = function(cb) { return this.once('connect', () => this._final(cb)); } - if (!this.readable || this._readableState.ended) { - debug('_final: ended, destroy', this._readableState); - cb(); - return this.destroy(); - } + if (!this._handle) + return cb(); debug('_final: not ended, call shutdown()'); - // otherwise, just shutdown, or destroy() if not possible - if (!this._handle || !this._handle.shutdown) { - cb(); - return this.destroy(); - } - - var err = defaultTriggerAsyncIdScope( - this[async_id_symbol], shutdownSocket, this, cb - ); + var req = new ShutdownWrap(); + req.oncomplete = afterShutdown; + req.handle = this._handle; + req.callback = cb; + var err = this._handle.shutdown(req); if (err) return this.destroy(errnoException(err, 'shutdown')); @@ -388,7 +373,7 @@ function afterShutdown(status, handle) { if (self.destroyed) return; - if (self._readableState.ended) { + if (!self.readable || self._readableState.ended) { debug('readableState ended, destroying'); self.destroy(); } |