summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2010-05-09 12:10:38 -0700
committerRyan Dahl <ry@tinyclouds.org>2010-05-09 12:10:42 -0700
commit1d28cfcfb9ad48e03a0b6c48eda97b5c91a5e3ae (patch)
treea8d1a4ccbe7e612f9f1f8b2094d7c233ca36b0af
parentd38d96eb610b50bdbfe869a6e7688e346984c0fa (diff)
downloadnodejs-1d28cfcfb9ad48e03a0b6c48eda97b5c91a5e3ae.tar.gz
nodejs-1d28cfcfb9ad48e03a0b6c48eda97b5c91a5e3ae.tar.bz2
nodejs-1d28cfcfb9ad48e03a0b6c48eda97b5c91a5e3ae.zip
Better logic for testing if an argument is a port
If you did server.listen('123') it would open a socket in the current directory called 123. Now it will interpret it as a port.
-rw-r--r--lib/net.js6
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/net.js b/lib/net.js
index 58494019e..1daf841ed 100644
--- a/lib/net.js
+++ b/lib/net.js
@@ -759,6 +759,8 @@ function doConnect (socket, port, host) {
};
}
+function isPort (x) { return parseInt(x) >= 0; }
+
// var stream = new Stream();
// stream.connect(80) - TCP connect to port 80 on the localhost
@@ -774,7 +776,7 @@ Stream.prototype.connect = function () {
self._connecting = true; // set false in doConnect
- if (parseInt(arguments[0]) >= 0) {
+ if (isPort(arguments[0])) {
// TCP
var port = arguments[0];
dns.lookup(arguments[1], function (err, ip, addressType) {
@@ -991,7 +993,7 @@ Server.prototype.listen = function () {
var self = this;
if (self.fd) throw new Error('Server already opened');
- if (typeof(arguments[0]) == 'string') {
+ if (!isPort(arguments[0])) {
// the first argument specifies a path
self.fd = socket('unix');
self.type = 'unix';