Skip to content
Browse files

[api] Update haibu-carapace to have a configurable set of reserved ports

  • Loading branch information...
1 parent 139e6d0 commit bd7bd247ae663b6bc3a5b55d68ce6f7ca890034c @indexzero indexzero committed Aug 7, 2011
Showing with 18 additions and 3 deletions.
  1. +4 −2 bin/carapace
  2. 0 bin/carapace-client
  3. +8 −0 lib/carapace.js
  4. +6 −1 lib/net.js
View
6 bin/carapace 100644 → 100755
@@ -3,7 +3,7 @@
var path = require('path'),
async = require('async'),
carapace = require('../lib/carapace');
-
+
//
// Extract the carapace CLI arguments for this
// process.
@@ -22,6 +22,9 @@ function onPluginError (info) {
process.exit(1);
}
+//
+// Setup the passthru arguments.
+//
var passthru = carapace.cli.extract(null, argv);
//
@@ -30,7 +33,6 @@ var passthru = carapace.cli.extract(null, argv);
// CLI options since
//
carapace.start(argv, function () {
-
function configure (next) {
if (!Array.isArray(argv.plugin)) {
argv.plugin = [argv.plugin];
View
0 bin/carapace-client 100644 → 100755
File mode changed.
View
8 lib/carapace.js
@@ -45,6 +45,14 @@ carapace.running = false;
carapace.listening = false;
//
+// Store a set of reserved ports for which the `net.js` implementation
+// should actually throw an error.
+//
+carapace.reserved = [
+ carapace['hook-port'] || carapace.defaults['hook-port']
+];
+
+//
// ### function listen (target, callback)
// #### @target {string|number} Socket path or port to listen on.
// #### @callback {function} Continuation to respond to when complete.
View
7 lib/net.js
@@ -70,7 +70,12 @@ net.Server.prototype._doListen = function () {
binding.bind(self.fd, arguments[0], arguments[1]);
}
catch (err) {
- if (err.code !== 'EADDRINUSE' || desired === carapace['hook-port']) {
+ //
+ // If this is not an `EADDRINUSE` error or the port is one of the
+ // `carapace.reserved` ports which should always throw an error,
+ // then throw the error.
+ //
+ if (err.code !== 'EADDRINUSE' || carapace.reserved.indexOf(desired) !== -1) {
self.close();
return self.emit('error', err);
}

0 comments on commit bd7bd24

Please sign in to comment.
Something went wrong with that request. Please try again.