Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
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
bnoordhuis authored and isaacs committed Jul 24, 2012
1 parent e4c9c9f commit 1513848
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions lib/net.js
Expand Up @@ -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);

Expand Down

0 comments on commit 1513848

Please sign in to comment.