From f54659cbc8448f5d513b00639f15a8a4009b2718 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 11 Feb 2018 03:08:21 +0100 Subject: [PATCH] net: simplify net.Socket#end() `writable` is already set by the streams side, and there is a handler waiting for the writable side to finish which already takes care of the other cleanup code that was previously there; both of these things can therefore be removed. PR-URL: https://github.com/nodejs/node/pull/18708 Reviewed-By: Luigi Pinca Reviewed-By: Ruben Bridgewater Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Matteo Collina --- lib/net.js | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/lib/net.js b/lib/net.js index 8b78d9249b7edd..c04d04473900d0 100644 --- a/lib/net.js +++ b/lib/net.js @@ -496,18 +496,10 @@ Socket.prototype._read = function(n) { }; -Socket.prototype.end = function(data, encoding) { - stream.Duplex.prototype.end.call(this, data, encoding); - this.writable = false; +Socket.prototype.end = function(data, encoding, callback) { + stream.Duplex.prototype.end.call(this, data, encoding, callback); DTRACE_NET_STREAM_END(this); LTTNG_NET_STREAM_END(this); - - // just in case we're waiting for an EOF. - if (this.readable && !this._readableState.endEmitted) - this.read(0); - else - maybeDestroy(this); - return this; };