summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLuigi Pinca <luigipinca@gmail.com>2018-02-24 09:44:42 +0100
committerLuigi Pinca <luigipinca@gmail.com>2018-03-07 16:05:30 +0100
commit4e86f9b5ab83cbabf43839385bf383e6a7ef7d19 (patch)
treea3036dc284441208c7e5c45aa76efd0ecef13e83 /lib
parentdf0716921e9bfd99f8e115dbaeee6199a93cd8c5 (diff)
downloadandroid-node-v8-4e86f9b5ab83cbabf43839385bf383e6a7ef7d19.tar.gz
android-node-v8-4e86f9b5ab83cbabf43839385bf383e6a7ef7d19.tar.bz2
android-node-v8-4e86f9b5ab83cbabf43839385bf383e6a7ef7d19.zip
net: do not inherit the no-half-open enforcer
`Socket.prototype.destroySoon()` is called as soon as `UV_EOF` is read if the `allowHalfOpen` option is disabled. This already works as a "no-half-open enforcer" so there is no need to inherit another from `stream.Duplex`. PR-URL: https://github.com/nodejs/node/pull/18974 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Chen Gang <gangc.cxy@foxmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/net.js11
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/net.js b/lib/net.js
index f2cb423f30..7fa1e20aed 100644
--- a/lib/net.js
+++ b/lib/net.js
@@ -64,6 +64,7 @@ const {
ERR_SOCKET_BAD_PORT,
ERR_SOCKET_CLOSED
} = errors.codes;
+const DuplexBase = require('internal/streams/duplex_base');
const dns = require('dns');
const kLastWriteQueueSize = Symbol('lastWriteQueueSize');
@@ -238,7 +239,11 @@ function Socket(options) {
// For backwards compat do not emit close on destroy.
options.emitClose = false;
- stream.Duplex.call(this, options);
+ // `DuplexBase` is just a slimmed down constructor for `Duplex` which allow
+ // us to not inherit the "no-half-open enforcer" as there is already one in
+ // place. Instances of `Socket` are still instances of `Duplex`, that is,
+ // `socket instanceof Duplex === true`.
+ DuplexBase.call(this, options);
if (options.handle) {
this._handle = options.handle; // private
@@ -263,8 +268,6 @@ function Socket(options) {
this._writev = null;
this._write = makeSyncWrite(fd);
}
- this.readable = options.readable !== false;
- this.writable = options.writable !== false;
} else {
// these will be set once there is a connection
this.readable = this.writable = false;
@@ -282,7 +285,7 @@ function Socket(options) {
this._writableState.decodeStrings = false;
// default to *not* allowing half open sockets
- this.allowHalfOpen = options && options.allowHalfOpen || false;
+ this.allowHalfOpen = options.allowHalfOpen || false;
// if we have a handle, then start the flow of data into the
// buffer. if not, then this will happen when we connect