diff --git a/lib/_stream_duplex.js b/lib/_stream_duplex.js index ef74c34c7e..c5a741c466 100644 --- a/lib/_stream_duplex.js +++ b/lib/_stream_duplex.js @@ -43,6 +43,12 @@ function Duplex(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) this.allowHalfOpen = false; diff --git a/lib/net.js b/lib/net.js index 89cb0d7275..41e28195ae 100644 --- a/lib/net.js +++ b/lib/net.js @@ -137,17 +137,17 @@ function Socket(options) { } stream.Duplex.call(this, options); - this.readable = this.writable = false; if (options.handle) { this._handle = options.handle; // private - } else if (typeof options.fd === 'undefined') { - this._handle = options && options.handle; // private - } else { + } else if (typeof options.fd !== 'undefined') { this._handle = createPipe(); this._handle.open(options.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; } this.onend = null; diff --git a/test/simple/test-stdio-readable-writable.js b/test/simple/test-stdio-readable-writable.js new file mode 100644 index 0000000000..5123f96887 --- /dev/null +++ b/test/simple/test-stdio-readable-writable.js @@ -0,0 +1,32 @@ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +var common = require('../common'); +var assert = require('assert'); + +assert(process.stdout.writable); +assert(!process.stdout.readable); + +assert(process.stderr.writable); +assert(!process.stderr.readable); + +assert(!process.stdin.writable); +assert(process.stdin.readable);