stdio: Set readable/writable flags properly
Set the readable/writable flags properly in net streams that have a handle passed in (such as TTY streams). Fix #4606
This commit is contained in:
Родитель
b48e303af0
Коммит
1528de2373
|
@ -43,6 +43,12 @@ function Duplex(options) {
|
||||||
Readable.call(this, options);
|
Readable.call(this, options);
|
||||||
Writable.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;
|
this.allowHalfOpen = true;
|
||||||
if (options && options.allowHalfOpen === false)
|
if (options && options.allowHalfOpen === false)
|
||||||
this.allowHalfOpen = false;
|
this.allowHalfOpen = false;
|
||||||
|
|
|
@ -137,17 +137,17 @@ function Socket(options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
stream.Duplex.call(this, options);
|
stream.Duplex.call(this, options);
|
||||||
this.readable = this.writable = false;
|
|
||||||
|
|
||||||
if (options.handle) {
|
if (options.handle) {
|
||||||
this._handle = options.handle; // private
|
this._handle = options.handle; // private
|
||||||
} else if (typeof options.fd === 'undefined') {
|
} else if (typeof options.fd !== 'undefined') {
|
||||||
this._handle = options && options.handle; // private
|
|
||||||
} else {
|
|
||||||
this._handle = createPipe();
|
this._handle = createPipe();
|
||||||
this._handle.open(options.fd);
|
this._handle.open(options.fd);
|
||||||
this.readable = options.readable !== false;
|
this.readable = options.readable !== false;
|
||||||
this.writable = options.writable !== false;
|
this.writable = options.writable !== false;
|
||||||
|
} else {
|
||||||
|
// these will be set once there is a connection
|
||||||
|
this.readable = this.writable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.onend = null;
|
this.onend = null;
|
||||||
|
|
|
@ -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);
|
Загрузка…
Ссылка в новой задаче