mirror of
https://github.com/nodejs/node.git
synced 2024-11-29 07:00:59 +01:00
stream: add no-half-open enforcer only if needed
The listener does not do anything if `allowHalfOpen` is enabled. Add it only when `allowHalfOpen` is disabled. PR-URL: https://github.com/nodejs/node/pull/18953 Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
584cfc9bae
commit
f2b9805f85
@ -58,10 +58,10 @@ function Duplex(options) {
|
||||
this.writable = false;
|
||||
|
||||
this.allowHalfOpen = true;
|
||||
if (options && options.allowHalfOpen === false)
|
||||
if (options && options.allowHalfOpen === false) {
|
||||
this.allowHalfOpen = false;
|
||||
|
||||
this.once('end', onend);
|
||||
this.once('end', onend);
|
||||
}
|
||||
}
|
||||
|
||||
Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', {
|
||||
@ -96,9 +96,8 @@ Object.defineProperty(Duplex.prototype, 'writableLength', {
|
||||
|
||||
// the no-half-open enforcer
|
||||
function onend() {
|
||||
// if we allow half-open state, or if the writable side ended,
|
||||
// then we're ok.
|
||||
if (this.allowHalfOpen || this._writableState.ended)
|
||||
// If the writable side ended, then we're ok.
|
||||
if (this._writableState.ended)
|
||||
return;
|
||||
|
||||
// no more data can be written.
|
||||
|
@ -34,7 +34,7 @@ server.on('connect', common.mustCall((req, socket, firstBodyChunk) => {
|
||||
assert.strictEqual(socket.listeners('close').length, 0);
|
||||
assert.strictEqual(socket.listeners('drain').length, 0);
|
||||
assert.strictEqual(socket.listeners('data').length, 0);
|
||||
assert.strictEqual(socket.listeners('end').length, 2);
|
||||
assert.strictEqual(socket.listeners('end').length, 1);
|
||||
assert.strictEqual(socket.listeners('error').length, 0);
|
||||
|
||||
socket.write('HTTP/1.1 200 Connection established\r\n\r\n');
|
||||
|
@ -29,6 +29,8 @@ const stream = new Duplex({ objectMode: true });
|
||||
assert(Duplex() instanceof Duplex);
|
||||
assert(stream._readableState.objectMode);
|
||||
assert(stream._writableState.objectMode);
|
||||
assert(stream.allowHalfOpen);
|
||||
assert.strictEqual(stream.listenerCount('end'), 0);
|
||||
|
||||
let written;
|
||||
let read;
|
||||
|
Loading…
Reference in New Issue
Block a user