Skip to content

Commit

Permalink
net,stream: remove DuplexBase
Browse files Browse the repository at this point in the history
`DuplexBase` was added to prevent the "no-half-open enforcer" from
being inherited by `net.Socket`. The main reason to use it instead
of `Duplex` was that it allowed to not copy the options object but
since commit 5e3f516 the options object is copyed anyway so it is
no longer useful.

PR-URL: #19779
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Daniel Bevenius <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
lpinca authored and targos committed Apr 12, 2018
1 parent f06b41e commit 03ab312
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 46 deletions.
26 changes: 22 additions & 4 deletions lib/_stream_duplex.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,33 @@
module.exports = Duplex;

const util = require('util');
const DuplexBase = require('internal/streams/duplex_base');

util.inherits(Duplex, DuplexBase);
const Readable = require('_stream_readable');
const Writable = require('_stream_writable');

util.inherits(Duplex, Readable);

{
// Allow the keys array to be GC'ed.
const keys = Object.keys(Writable.prototype);
for (var v = 0; v < keys.length; v++) {
const method = keys[v];
if (!Duplex.prototype[method])
Duplex.prototype[method] = Writable.prototype[method];
}
}

function Duplex(options) {
if (!(this instanceof Duplex))
return new Duplex(options);

DuplexBase.call(this, options);
Readable.call(this, options);
Writable.call(this, options);

if (options && options.readable === false)
this.readable = false;

if (options && options.writable === false)
this.writable = false;

this.allowHalfOpen = true;
if (options && options.allowHalfOpen === false) {
Expand Down
30 changes: 0 additions & 30 deletions lib/internal/streams/duplex_base.js

This file was deleted.

23 changes: 12 additions & 11 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ const { async_id_symbol } = process.binding('async_wrap');
const { newUid, defaultTriggerAsyncIdScope } = require('internal/async_hooks');
const { nextTick } = require('internal/process/next_tick');
const errors = require('internal/errors');
const DuplexBase = require('internal/streams/duplex_base');
const dns = require('dns');

const kLastWriteQueueSize = Symbol('lastWriteQueueSize');
Expand Down Expand Up @@ -209,14 +208,19 @@ function Socket(options) {

if (typeof options === 'number')
options = { fd: options }; // Legacy interface.
else if (options === undefined)
options = {};
else
options = util._extend({}, options);

const allowHalfOpen = options.allowHalfOpen;

// `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);
// Prevent the "no-half-open enforcer" from being inherited from `Duplex`.
options.allowHalfOpen = true;
// For backwards compat do not emit close on destroy.
options.emitClose = false;
stream.Duplex.call(this, options);

// Default to *not* allowing half open sockets.
this.allowHalfOpen = Boolean(allowHalfOpen);

if (options.handle) {
this._handle = options.handle; // private
Expand Down Expand Up @@ -258,9 +262,6 @@ function Socket(options) {
// handle strings directly
this._writableState.decodeStrings = false;

// default to *not* allowing half open sockets
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
if (this._handle && options.readable !== false) {
Expand Down
1 change: 0 additions & 1 deletion node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@
'lib/internal/vm/Module.js',
'lib/internal/streams/lazy_transform.js',
'lib/internal/streams/BufferList.js',
'lib/internal/streams/duplex_base.js',
'lib/internal/streams/legacy.js',
'lib/internal/streams/destroy.js',
'lib/internal/wrap_js_stream.js',
Expand Down

0 comments on commit 03ab312

Please sign in to comment.