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
|
// the user has called .end(), and all the bytes have been
|
||||||
// sent out to the other side.
|
// sent out to the other side.
|
||||||
Socket.prototype._final = function(cb) {
|
Socket.prototype._final = function(cb) {
|
||||||
@ -353,23 +345,16 @@ Socket.prototype._final = function(cb) {
|
|||||||
return this.once('connect', () => this._final(cb));
|
return this.once('connect', () => this._final(cb));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.readable || this._readableState.ended) {
|
if (!this._handle)
|
||||||
debug('_final: ended, destroy', this._readableState);
|
return cb();
|
||||||
cb();
|
|
||||||
return this.destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
debug('_final: not ended, call shutdown()');
|
debug('_final: not ended, call shutdown()');
|
||||||
|
|
||||||
// otherwise, just shutdown, or destroy() if not possible
|
var req = new ShutdownWrap();
|
||||||
if (!this._handle || !this._handle.shutdown) {
|
req.oncomplete = afterShutdown;
|
||||||
cb();
|
req.handle = this._handle;
|
||||||
return this.destroy();
|
req.callback = cb;
|
||||||
}
|
var err = this._handle.shutdown(req);
|
||||||
|
|
||||||
var err = defaultTriggerAsyncIdScope(
|
|
||||||
this[async_id_symbol], shutdownSocket, this, cb
|
|
||||||
);
|
|
||||||
|
|
||||||
if (err)
|
if (err)
|
||||||
return this.destroy(errnoException(err, 'shutdown'));
|
return this.destroy(errnoException(err, 'shutdown'));
|
||||||
@ -388,7 +373,7 @@ function afterShutdown(status, handle) {
|
|||||||
if (self.destroyed)
|
if (self.destroyed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (self._readableState.ended) {
|
if (!self.readable || self._readableState.ended) {
|
||||||
debug('readableState ended, destroying');
|
debug('readableState ended, destroying');
|
||||||
self.destroy();
|
self.destroy();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user