Permalink
Browse files

Revert "[fix] always listen to wildcard address"

This reverts commit 19decba.

Conflicts:

	lib/net.js
  • Loading branch information...
1 parent 19982f5 commit c9f31ba89ff1f97c5d82bad10e8d14027a0a58e9 @mmalecki mmalecki committed May 2, 2012
Showing with 26 additions and 4 deletions.
  1. +26 −4 lib/net.js
View
@@ -20,6 +20,28 @@ function toPort(x) {
}
//
+// ### function nextPort (port)
+// #### @port {Number} Port to increment from.
+// Gets the next port in sequence from the
+// specified `port`.
+//
+function nextPort(port) {
+ if (!port) {
+ return 8000;
+ }
+
+ //
+ // Find the next port that we are not supposed to ignore or cause errors on
+ //
+ var unavailable = carapace.ports.ignore.concat(carapace.ports.throw);
+ do {
+ port = port + 1;
+ } while (unavailable.indexOf(port) !== -1);
+
+ return port;
+}
+
+//
// ### functon reservedPort
// #### @desired {Number} Desired port to bind to.
// Helper function which will emit an error if the
@@ -88,18 +110,18 @@ exports._doListen = function overrideNet() {
// Since desired is not on a throwing port
// we want to skip ports in both throw and ignore
//
- current = 0;
+ current = desired ? desired : nextPort(desired);
for (;;) {
try {
- binding.bind(self.fd, 0, '0.0.0.0');
+ binding.bind(self.fd, current, addr);
break;
}
catch (err) {
//
// Find the next port we are not supposed to throw up on or ignore
//
- current = 0;
+ current = nextPort(current);
//
// If this is not an `EADDRINUSE` error or the port is in
@@ -290,7 +312,7 @@ exports._listen2 = function overrideNet() {
// Call original _listen2 function.
//
process.nextTick(function () {
- _listen2.call(self, '0.0.0.0', 0, addressType);
+ _listen2.call(self, address, port, addressType);
});
};
};

0 comments on commit c9f31ba

Please sign in to comment.