Browse Source

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.
v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
1d28cfcfb9
  1. 6
      lib/net.js

6
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';

Loading…
Cancel
Save