};
}
-function isPort (x) { return parseInt(x) >= 0; }
+function toPort (x) { return (x = Number(x)) >= 0 ? x : false }
// var stream = new Stream();
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);
doConnect(self, port, ip);
}
});
- } else {
- // UNIX
- self.fd = socket('unix');
- self.type = 'unix';
-
- setImplmentationMethods(this);
- doConnect(self, arguments[0]);
}
};
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';
// 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);