From 0866ef115f6a3cb9426d0a5f7677c5e3ed0bf686 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Sat, 14 Mar 2020 22:18:07 +0100 Subject: [PATCH] net: don't explicitly set readable/writable --- lib/net.js | 21 +++++++++----------- test/parallel/test-net-socket-constructor.js | 10 +++++----- test/parallel/test-net-socket-setnodelay.js | 15 +++++++++----- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/lib/net.js b/lib/net.js index 0d3cc29db64fc4..a8f99412b609bb 100644 --- a/lib/net.js +++ b/lib/net.js @@ -285,8 +285,6 @@ function Socket(options) { else options = { ...options }; - options.readable = options.readable || false; - options.writable = options.writable || false; const { allowHalfOpen } = options; // Prevent the "no-half-open enforcer" from being inherited from `Duplex`. @@ -366,7 +364,7 @@ function Socket(options) { // If we have a handle, then start the flow of data into the // buffer. if not, then this will happen when we connect - if (this._handle && options.readable !== false) { + if (this._handle) { if (options.pauseOnCreate) { // Stop the handle from reading and pause the stream this._handle.reading = false; @@ -655,8 +653,6 @@ Socket.prototype._destroy = function(exception, cb) { this.connecting = false; - this.readable = this.writable = false; - for (let s = this; s !== null; s = s._parent) { clearTimeout(s[kTimeout]); } @@ -968,7 +964,6 @@ Socket.prototype.connect = function(...args) { this._unrefTimer(); this.connecting = true; - this.writable = true; if (pipe) { validateString(path, 'options.path'); @@ -1120,9 +1115,13 @@ function afterConnect(status, handle, req, readable, writable) { self._sockname = null; if (status === 0) { - self.readable = readable; - if (!self._writableState.ended) - self.writable = writable; + if (!readable) { + self.push(null); + self.read(); + } + if (!writable) { + self.end(); + } self._unrefTimer(); self.emit('connect'); @@ -1544,9 +1543,7 @@ function onconnection(err, clientHandle) { const socket = new Socket({ handle: clientHandle, allowHalfOpen: self.allowHalfOpen, - pauseOnCreate: self.pauseOnConnect, - readable: true, - writable: true + pauseOnCreate: self.pauseOnConnect }); self._connections++; diff --git a/test/parallel/test-net-socket-constructor.js b/test/parallel/test-net-socket-constructor.js index d1ac8b35121826..0454a6fbe1233e 100644 --- a/test/parallel/test-net-socket-constructor.js +++ b/test/parallel/test-net-socket-constructor.js @@ -27,12 +27,12 @@ function test(sock, readable, writable) { } if (cluster.isMaster) { - test(undefined, false, false); + test(undefined, true, true); const server = net.createServer(common.mustCall((socket) => { socket.unref(); test(socket, true, true); - test({ handle: socket._handle }, false, false); + test({ handle: socket._handle }, true, true); test({ handle: socket._handle, readable: true, writable: true }, true, true); server.close(); @@ -45,7 +45,7 @@ if (cluster.isMaster) { socket.end(); })); - test(socket, false, true); + test(socket, true, true); })); cluster.setupMaster({ @@ -58,8 +58,8 @@ if (cluster.isMaster) { assert.strictEqual(signal, null); })); } else { - test(4, false, false); - test({ fd: 5 }, false, false); + test(4, true, true); + test({ fd: 5 }, true, true); test({ fd: 6, readable: true, writable: true }, true, true); process.disconnect(); } diff --git a/test/parallel/test-net-socket-setnodelay.js b/test/parallel/test-net-socket-setnodelay.js index e11d89daec58de..da1d9a4a314882 100644 --- a/test/parallel/test-net-socket-setnodelay.js +++ b/test/parallel/test-net-socket-setnodelay.js @@ -13,28 +13,32 @@ const genSetNoDelay = (desiredArg) => (enable) => { // setNoDelay should default to true let socket = new net.Socket({ handle: { - setNoDelay: common.mustCall(genSetNoDelay(true)) + setNoDelay: common.mustCall(genSetNoDelay(true)), + readStart() {} } }); socket.setNoDelay(); socket = new net.Socket({ handle: { - setNoDelay: common.mustCall(genSetNoDelay(true), 1) + setNoDelay: common.mustCall(genSetNoDelay(true), 1), + readStart() {} } }); truthyValues.forEach((testVal) => socket.setNoDelay(testVal)); socket = new net.Socket({ handle: { - setNoDelay: common.mustNotCall() + setNoDelay: common.mustNotCall(), + readStart() {} } }); falseyValues.forEach((testVal) => socket.setNoDelay(testVal)); socket = new net.Socket({ handle: { - setNoDelay: common.mustCall(() => {}, 3) + setNoDelay: common.mustCall(() => {}, 3), + readStart() {} } }); truthyValues.concat(falseyValues).concat(truthyValues) @@ -44,7 +48,8 @@ truthyValues.concat(falseyValues).concat(truthyValues) // In the case below, if it is called an exception will be thrown socket = new net.Socket({ handle: { - setNoDelay: null + setNoDelay: null, + readStart() {} } }); const returned = socket.setNoDelay(true);