Skip to content

Commit

Permalink
Allow Strings for ports on net.Server.listen
Browse files Browse the repository at this point in the history
  • Loading branch information
bmeck authored and ry committed Aug 30, 2010
1 parent db23af0 commit d5214b3
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ function doConnect (socket, port, host) {
};
}

function isPort (x) { return parseInt(x) >= 0; }
function toPort (x) { return (x = Number(x)) >= 0 ? x : false }


// var stream = new Stream();
Expand All @@ -873,9 +873,16 @@ Stream.prototype.connect = function () {

self._connecting = true; // set false in doConnect

if (isPort(arguments[0])) {
var port = toPort(arguments[0])
if (port === false) {
// UNIX
self.fd = socket('unix');
self.type = 'unix';

setImplmentationMethods(this);
doConnect(self, arguments[0]);
} else {
// TCP
var port = arguments[0];
dns.lookup(arguments[1], function (err, ip, addressType) {
if (err) {
self.emit('error', err);
Expand All @@ -885,13 +892,6 @@ Stream.prototype.connect = function () {
doConnect(self, port, ip);
}
});
} else {
// UNIX
self.fd = socket('unix');
self.type = 'unix';

setImplmentationMethods(this);
doConnect(self, arguments[0]);
}
};

Expand Down Expand Up @@ -1109,7 +1109,8 @@ Server.prototype.listen = function () {
self.addListener('listening', lastArg);
}

if (!isPort(arguments[0])) {
var port = toPort(arguments[0])
if (port === false) {
// the first argument specifies a path
self.fd = socket('unix');
self.type = 'unix';
Expand Down Expand Up @@ -1144,13 +1145,12 @@ Server.prototype.listen = function () {
// The port can be found with server.address()
self.type = 'tcp4';
self.fd = socket(self.type);
bind(self.fd, arguments[0]);
bind(self.fd, port);
process.nextTick(function () {
self._doListen();
});
} else {
// the first argument is the port, the second an IP
var port = arguments[0];
dns.lookup(arguments[1], function (err, ip, addressType) {
if (err) {
self.emit('error', err);
Expand Down

0 comments on commit d5214b3

Please sign in to comment.