Browse Source

streams2: Fix duplex no-half-open logic

v0.9.4-release
isaacs 12 years ago
parent
commit
5856823223
  1. 27
      lib/_stream_duplex.js

27
lib/_stream_duplex.js

@ -47,38 +47,17 @@ function Duplex(options) {
if (options && options.allowHalfOpen === false)
this.allowHalfOpen = false;
this.once('finish', onfinish);
this.once('end', onend);
}
// the no-half-open enforcers.
function onfinish() {
// if we allow half-open state, or if the readable side ended,
// then we're ok.
if (this.allowHalfOpen || this._readableState.ended)
return;
// mark that we're done.
this._readableState.ended = true;
// tell the user
if (this._readableState.length === 0)
this.emit('end');
else
this.emit('readable');
}
// 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)
return;
// just in case the user is about to call write() again.
this.write = function() {
return false;
};
// no more data can be written.
this.end();
// But allow more writes to happen in this tick.
process.nextTick(this.end.bind(this));
}

Loading…
Cancel
Save