Skip to content
Browse files

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.
  • Loading branch information...
1 parent 19aa05f commit 418668a92d449982e979ed5a3920a6facd2983fe @bnoordhuis committed Jul 17, 2012
Showing with 16 additions and 10 deletions.
  1. +16 −10 lib/net.js
View
26 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);

0 comments on commit 418668a

Please sign in to comment.
Something went wrong with that request. Please try again.