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>
This commit is contained in:
parent
9c6b7f7b1d
commit
b7e6ccd0cc
31
lib/net.js
31
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();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user