summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2012-07-17 15:16:23 +0200
committerisaacs <i@izs.me>2012-07-24 15:53:22 -0700
commit1513848f8801d7d1141c10c4960b6bfe47a53ed2 (patch)
tree8808d5041482729deddffe99b841501674e1a59d
parente4c9c9f412ca64435fbe93a2700d569b84ba7b36 (diff)
downloadnode-new-1513848f8801d7d1141c10c4960b6bfe47a53ed2.tar.gz
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.
-rw-r--r--lib/net.js26
1 files changed, 16 insertions, 10 deletions
diff --git a/lib/net.js b/lib/net.js
index b4934e3269..7fe892f65d 100644
--- a/lib/net.js
+++ b/lib/net.js
@@ -131,19 +131,25 @@ function Socket(options) {
Stream.call(this);
- if (typeof options == 'number') {
- // Legacy interface.
- var fd = options;
+ switch (typeof options) {
+ case 'number':
+ options = { fd: options }; // Legacy interface.
+ break;
+ case 'undefined':
+ options = {};
+ break;
+ }
+
+ if (typeof options.fd === 'undefined') {
+ this._handle = options && options.handle; // private
+ } else {
this._handle = createPipe();
- this._handle.open(fd);
+ this._handle.open(options.fd);
this.readable = this.writable = true;
- initSocketHandle(this);
- } else {
- // private
- this._handle = options && options.handle;
- initSocketHandle(this);
- this.allowHalfOpen = options && options.allowHalfOpen;
}
+
+ initSocketHandle(this);
+ this.allowHalfOpen = options && options.allowHalfOpen;
}
util.inherits(Socket, Stream);