net: fix Socket({ fd: 42 }) api
Make the implementation match the documentation. This should work: var s = new net.Socket({ fd: 42, allowHalfOpen: true }; And now it does.
This commit is contained in:
parent
e4c9c9f412
commit
1513848f88
30
lib/net.js
30
lib/net.js
@ -131,19 +131,25 @@ function Socket(options) {
|
|||||||
|
|
||||||
Stream.call(this);
|
Stream.call(this);
|
||||||
|
|
||||||
if (typeof options == 'number') {
|
switch (typeof options) {
|
||||||
// Legacy interface.
|
case 'number':
|
||||||
var fd = options;
|
options = { fd: options }; // Legacy interface.
|
||||||
this._handle = createPipe();
|
break;
|
||||||
this._handle.open(fd);
|
case 'undefined':
|
||||||
this.readable = this.writable = true;
|
options = {};
|
||||||
initSocketHandle(this);
|
break;
|
||||||
} else {
|
|
||||||
// private
|
|
||||||
this._handle = options && options.handle;
|
|
||||||
initSocketHandle(this);
|
|
||||||
this.allowHalfOpen = options && options.allowHalfOpen;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof options.fd === 'undefined') {
|
||||||
|
this._handle = options && options.handle; // private
|
||||||
|
} else {
|
||||||
|
this._handle = createPipe();
|
||||||
|
this._handle.open(options.fd);
|
||||||
|
this.readable = this.writable = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
initSocketHandle(this);
|
||||||
|
this.allowHalfOpen = options && options.allowHalfOpen;
|
||||||
}
|
}
|
||||||
util.inherits(Socket, Stream);
|
util.inherits(Socket, Stream);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user